@Override public boolean onOptionsItemSelected(MenuItem item) { // The action bar home/up action should open or close the drawer. // ActionBarDrawerToggle will take care of this. switch (item.getItemId()) { case android.R.id.home: if (mDrawerLayout.isDrawerOpen(mDrawerList)) { mDrawerLayout.closeDrawer(mDrawerList); } else { mDrawerLayout.openDrawer(mDrawerList); SharedPreferences myPrefs = getSharedPreferences("myPrefs", MODE_PRIVATE); if (!myPrefs.contains("drawerFinished")) { myPrefs .edit() .putString("drawerFinished", "true") .commit(); // Open the drawer on first install of app only } } return true; case R.id.action_settings: Intent intent = new Intent(this, settingsActivity.class); startActivity(intent); return true; default: return super.onOptionsItemSelected(item); } }
public void reload(boolean open) { Activity act = getActivity(); if (act != null) { mAdapter.reload(act); if (open) mDrawerLayout.openDrawer(Gravity.START); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle != null && mDrawerToggle.onOptionsItemSelected(item)) return true; if (android.R.id.home == item.getItemId()) { if (mDrawerLayout.isDrawerVisible(GravityCompat.START)) mDrawerLayout.closeDrawers(); else mDrawerLayout.openDrawer(GravityCompat.START); return true; } // 关于 if (item.getItemId() == R.id.about) AboutWebFragment.launchAbout(this); // 意见反馈 else if (item.getItemId() == R.id.feedback) PublishActivity.publishFeedback(this); // 好友分组 else if (item.getItemId() == R.id.friendGroups) GroupSortFragment.lanuch(this); // 搜索用户或者微博 // else if (item.getItemId() == R.id.search) // SearchActivity.launch(this); // 退出 else if (item.getItemId() == R.id.exitapp) finish(); // 新微博 else if (item.getItemId() == R.id.publish) PublishActivity.publishStatus(this, null); // 搜人 else if (item.getItemId() == R.id.search_user) SearchUserFragment.launch(this); // 搜微博 else if (item.getItemId() == R.id.search_status) SearchTopicsFragment.launch(this); // 开始离线 else if (item.getItemId() == R.id.toggle_offline) OfflineUtils.toggleOffline(this); return super.onOptionsItemSelected(item); }
/** при нажатии кнопки Home появляется меню */ @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { mNavigationDrawer.openDrawer(GravityCompat.START); } return super.onOptionsItemSelected(item); }
public void setUp(int fragmentid, DrawerLayout layout, Toolbar tool) { containerview = getActivity().findViewById(fragmentid); mDralayout = layout; mtoggle = new ActionBarDrawerToggle( getActivity(), layout, tool, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!muserlearned) { muserlearned = true; savetoprefrence(getActivity(), keyuser, muserlearned + ""); // saved to pref method } getActivity().invalidateOptionsMenu(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); getActivity().invalidateOptionsMenu(); } }; if (!muserlearned && !mfromsaved) { mDralayout.openDrawer(containerview); } mDralayout.setDrawerListener(mtoggle); mDralayout.post( new Runnable() { @Override public void run() { mtoggle.syncState(); } }); }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { Boolean isDrawerOpen = mDrawerLayout.isDrawerOpen(Gravity.RIGHT); Boolean isMenuListFocused = false; if (mList != null) { isMenuListFocused = mList.hasFocus(); } View view = this.getCurrentFocus(); if (isDrawerOpen) { if (!view.getClass() .getName() .equalsIgnoreCase("com.android.internal.view.menu.ActionMenuItemView")) { mDrawerLayout.closeDrawers(); mDrawerLayout.getChildAt(0).requestFocus(); } } else { if (KeyEvent.KEYCODE_DPAD_UP == keyCode) { // action bar mDrawerLayout.getChildAt(1).requestFocus(); } else if (KeyEvent.KEYCODE_DPAD_DOWN == keyCode) { // grid view mDrawerLayout.getChildAt(0).requestFocus(); } else if (KeyEvent.KEYCODE_DPAD_LEFT == keyCode) { } else if (KeyEvent.KEYCODE_MENU == keyCode) { if (!mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) { mDrawerLayout.openDrawer(Gravity.RIGHT); } else { mDrawerLayout.closeDrawer(Gravity.RIGHT); } } } return super.onKeyDown(keyCode, event); }
public void toggleDrawer() { if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) { mDrawerLayout.closeDrawer(Gravity.RIGHT); } else { mDrawerLayout.openDrawer(Gravity.RIGHT); } }
public void Drawer() { if (mDrawerLayout.isDrawerOpen(mDrawerList)) { mDrawerLayout.closeDrawer(mDrawerList); } else { mDrawerLayout.openDrawer(mDrawerList); } }
public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); switch (itemId) { // 如果ActionBar设置setDisplayHomeAsUpEnabled为true,则可以监听到前面的箭头图标 case android.R.id.home: if (drawerLayout.isDrawerOpen(Gravity.LEFT)) { drawerLayout.closeDrawers(); } else { drawerLayout.openDrawer(Gravity.LEFT); } break; case R.id.action_settings: startActivity(new Intent(this, SettingActivity.class)); break; case R.id.action_about: startActivity(new Intent(this, AboutActivity.class)); break; case R.id.action_share: startActivity( ShareActivity.makeIntent( this, "干货集中营", "每日分享妹子图 和 技术干货,还有供大家中午休息的休闲视频。", "http://gank.io")); break; default: break; } return super.onOptionsItemSelected(item); }
public void setOpen(boolean isOpen) { if (isOpen) { drawerLayout.openDrawer(GravityCompat.START); } else { drawerLayout.closeDrawer(GravityCompat.START); } }
public void setUp(int fragmentId, final DrawerLayout drawerLayout) { fragmentContainerView = baseActivity.findViewById(fragmentId); this.drawerLayout = drawerLayout; drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); ActionBar actionBar = baseActivity.getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); drawerToggle = new QMActionBarDrawerToggle( baseActivity, drawerLayout, R.drawable.ic_drawer, R.string.nvd_open, R.string.nvd_close); if (!userLearnedDrawer && !fromSavedInstanceState) { drawerLayout.openDrawer(fragmentContainerView); } drawerLayout.post( new Runnable() { @Override public void run() { drawerToggle.syncState(); } }); drawerLayout.setDrawerListener(drawerToggle); }
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); mDrawerToggle = new ActionBarDrawerToggle( getActivity(), mDrawerLayout, R.drawable.ic_drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().invalidateOptionsMenu(); if (mCallbacks != null) { mCallbacks.onDrawerclose(); } } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } if (mCallbacks != null) { mCallbacks.onDraweropen(); } } }; if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mFragmentContainerView); } mDrawerLayout.post( new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
public void toggleMenu() { if (isDrawerOpen() && mDrawerLayout != null && mFragmentContainerView != null) { mDrawerLayout.closeDrawer(mFragmentContainerView); } else if (mDrawerLayout != null && mFragmentContainerView != null) { mDrawerLayout.openDrawer(mFragmentContainerView); } }
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) { if (!contentView.isDrawerOpen(browserListView)) contentView.openDrawer(browserListView); else contentView.closeDrawer(browserListView); return true; } if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { // Finder is active, close it then if (bar.findViewById(R.id.finder) != null) { SetupLayouts.dismissFindBar(); return true; } else { CustomWebView WV = (CustomWebView) webLayout.findViewById(R.id.browser_page); if (WV != null) { if (WV.canGoBack()) { if (!MainActivity.contentView.isDrawerOpen(MainActivity.browserListView)) WV.goBack(); return true; } } if ((WV != null && WV.canGoBack() == false) || webWindows.size() == 0) { doExiting(); } } return true; } return false; };
public void toggleDrawer() { if (drawerLayout.isDrawerOpen(GravityCompat.START)) { drawerLayout.closeDrawer(GravityCompat.START); } else { drawerLayout.openDrawer(GravityCompat.START); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { if (isDrawerOpen()) mDrawerLayout.closeDrawer(mFragmentContainerView); else mDrawerLayout.openDrawer(mFragmentContainerView); } return super.onOptionsItemSelected(item); }
@OnClick(R.id.bar_logo) public void bar_logo() { if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mDrawerLayout.closeDrawer(GravityCompat.START); } else { mDrawerLayout.openDrawer(GravityCompat.START); } }
private void toggleDrawer() { if (drawerLayout.isDrawerOpen(leftDrawer)) { drawerLayout.closeDrawer(leftDrawer); } else { drawerLayout.openDrawer(leftDrawer); } updateHeader(getCurrentFragment()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pac_console); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, R.drawable.ic_drawer, R.string.app_name, R.string.app_name) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { // TODO Update the actionbar title if (mSelectedItem != null) { getActionBar().setTitle(mSelectedItem.title); } } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { // TODO Update the actionbar title getActionBar().setTitle("PAC Console"); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerList = (ListView) findViewById(R.id.left_drawer); // make our list for the drawer createDrawList(); mDrawerList.setAdapter(new drawerItemAdapter(this, R.layout.drawer_list_item, mGameTitles)); mDrawerList.setOnItemClickListener( new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // ATTACH req fragment to content view attachFrag(arg2); mDrawerList.setSelection(arg2); } }); // setup the drawer tab getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); mDrawerLayout.openDrawer(mDrawerList); getActionBar().setTitle("PAC Console"); // args.putInt(DragFrag.ARG_PORT_NUMBER, mTrackTitles.get(position).port); // fragment.setArguments(args); // Insert the fragment by replacing any existing fragment }
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.rbtn_pink) { mDrawer.setScrimColor(getResources().getColor(R.color.color_e81d62)); // 设置滑动时渐变的阴影颜色 } else if (checkedId == R.id.rbtn_green) { mDrawer.setScrimColor(getResources().getColor(R.color.color_4bae4f)); } else if (checkedId == R.id.rbtn_blue) { mDrawer.setScrimColor(getResources().getColor(R.color.color_2095f2)); } else if (checkedId == R.id.rbtn_from_left) { mDrawer.openDrawer(Gravity.LEFT); // 打开菜单栏 } else if (checkedId == R.id.rbtn_from_right) { mDrawer.openDrawer(Gravity.RIGHT); } }
public void setRootsDrawerOpen(boolean open) { if (!mShowAsDialog) { if (open) { mDrawerLayout.openDrawer(mRootsDrawer); } else { mDrawerLayout.closeDrawer(mRootsDrawer); } } }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (drawerToggle != null && drawerToggle.onOptionsItemSelected(item)) return true; if (android.R.id.home == item.getItemId()) { if (mDrawerLayout.isDrawerVisible(GravityCompat.START)) mDrawerLayout.closeDrawers(); else mDrawerLayout.openDrawer(GravityCompat.START); return true; } // 关于 // if (item.getItemId() == R.id.about) // AboutWebFragment.launchAbout(this); // 意见反馈 // else if (item.getItemId() == R.id.feedback) // PublishActivity.publishFeedback(this); // 退出 if (item.getItemId() == R.id.exitapp) { finish(); MobclickAgent.onEvent(this, "exitapp"); } // 新微博 else if (item.getItemId() == R.id.publish) PublishActivity.publishStatus(this, null); // 开始离线 else if (item.getItemId() == R.id.toggle_offline) { OfflineUtils.toggleOffline(this); MobclickAgent.onEvent(this, "toggle_offline"); } // 停止离线 else if (item.getItemId() == R.id.stop_offline) { OfflineService.stopOffline(); MobclickAgent.onEvent(this, "stop_offline"); } // 通知设置 else if (item.getItemId() == R.id.notification_settings) NotificationSettingsFragment.launch(this); // 搜索 else if (item.getItemId() == R.id.search) { new IAction( MainActivity.this, new WebLoginAction(MainActivity.this, BizFragment.createBizFragment(this))) { @Override public void doAction() { SearchFragment.launch(MainActivity.this, ""); MobclickAgent.onEvent(MainActivity.this, "toggle_search"); } }.run(); } return super.onOptionsItemSelected(item); }
public static void manipulateDrawer() { if (y == 0) { mDrawerLayout.openDrawer(Gravity.LEFT); y = -1; } else { mDrawerLayout.closeDrawer(Gravity.LEFT); y = 0; } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: mDrawerLayout.openDrawer(GravityCompat.START); return true; } return super.onOptionsItemSelected(item); }
// 如果导航是显示状态则隐藏,如果是隐藏则显示 private void showOrHiddenNav() { if (mDrawerLayout.isDrawerOpen(relativelayout)) { mDrawerLayout.closeDrawer(relativelayout); getActionBar().setTitle(R.string.app_home); } else { mDrawerLayout.openDrawer(relativelayout); getActionBar().setTitle(R.string.app_name); } }
/** * This method should be called by your <code>Activity</code>'s {@link * android.app.Activity#onOptionsItemSelected(android.view.MenuItem) onOptionsItemSelected} * method. If it returns true, your <code>onOptionsItemSelected</code> method should return true * and skip further processing. * * @param item the MenuItem instance representing the selected menu item * @return true if the event was handled and further processing should not occur */ public boolean onOptionsItemSelected(MenuItem item) { if (item != null && item.getItemId() == ID_HOME && mDrawerIndicatorEnabled) { if (mDrawerLayout.isDrawerVisible(GravityCompat.START)) { mDrawerLayout.closeDrawer(GravityCompat.START); } else { mDrawerLayout.openDrawer(GravityCompat.START); } } return false; }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. if (item.getItemId() == android.R.id.home) { drawerLayout.openDrawer(GravityCompat.START); } return super.onOptionsItemSelected(item); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // Open the navigation drawer when the home icon is selected from the toolbar. mDrawerLayout.openDrawer(GravityCompat.START); return true; } return super.onOptionsItemSelected(item); }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { if (mDrawerLayout.isDrawerOpen(mDrawerList)) { mDrawerLayout.closeDrawer(mDrawerList); } else { mDrawerLayout.openDrawer(mDrawerList); } } return super.onOptionsItemSelected(item); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mLeftDrawerList = (LinearLayout) findViewById(R.id.leftNavdrawer); llMainContent = (LinearLayout) findViewById(R.id.llMainContent); tvSelectedMenuLookUpItem = (TextView) findViewById(R.id.tvSelectedMenuLookUpItem); lvMenuLookUpItems = (ListView) findViewById(R.id.lvMenuLookUpItems); ArrayList<MenuLookUpItem> menuLookUpItems = StaticData.GetMenuLookUpItems(); menuLookUpItemAdapter = new MenuLookUpItemAdapter(MainActivity.this, menuLookUpItems); lvMenuLookUpItems.setAdapter(menuLookUpItemAdapter); lvMenuLookUpItems.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { numberOfSelectItem++; checkForShowInterstital(); MenuLookUpItem menuLookUpItem = (MenuLookUpItem) view.getTag(); if (menuLookUpItem.hasAction()) { tvSelectedMenuLookUpItem.setText(menuLookUpItem.getName()); // vwMainContent.ad llMainContent.removeAllViews(); mDrawerLayout.closeDrawer(mLeftDrawerList); llMainContent.addView( menuLookUpItem.getView(MainActivity.this), 0, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); } else { Toast.makeText(MainActivity.this, "Not Implemented Yet", Toast.LENGTH_LONG).show(); } } }); numberOfSelectItem = 1; timeForRun = 0; savedValues = new SavedValues(this); if (savedValues.getRecordFirstRun() == 0) { isFirstRun = true; savedValues.setRecordFirstRun(Calendar.getInstance().getTime().getTime()); } else { isFirstRun = false; } mAdView = (AdView) this.findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); mDrawerLayout.openDrawer(mLeftDrawerList); }