So I have tabs that I want to hide when the Navigation Drawer starts opening. The code I have hides them when it finished opening, but it's not what I want.
mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close ) { @Override public void onDrawerClosed(View view) { invalidateOptionsMenu(); setActionBarMode(ActionBar.NAVIGATION_MODE_TABS); } @Override public void onDrawerOpened(View drawerView) { invalidateOptionsMenu(); setActionBarMode(ActionBar.NAVIGATION_MODE_STANDARD); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); Here's what I tried:
onClickListener to mDrawerLayout. onClick never gets calledonTouchListener to mDrawerLayout. onTouch never gets calledActionBarDrawerToggle and DrawerLayout classes. Could not find anything like onDrawerStartedOpening.To use a DrawerLayout, position your primary content view as the first child with width and height of match_parent and no layout_gravity> . Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.
DEPRECATED: See other answers for a more suitable solution
There are 2 possible ways to do that:
onDrawerSlide(View drawerView, float slideOffset) callbackslideOffset changes from 0 to 1. 1 means it is completely open, 0 - closed.
Once offset changes from 0 to !0 - it means it started opening process. Something like:
mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close ) { @Override public void onDrawerSlide(View drawerView, float slideOffset) { if (slideOffset == 0 && getActionBar().getNavigationMode() == ActionBar.NAVIGATION_MODE_STANDARD) { // drawer closed getActionBar() .setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); invalidateOptionsMenu(); } else if (slideOffset != 0 && getActionBar().getNavigationMode() == ActionBar.NAVIGATION_MODE_TABS) { // started opening getActionBar() .setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); invalidateOptionsMenu(); } super.onDrawerSlide(drawerView, slideOffset); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); onDrawerStateChanged(int newState) callbackYou need to listen to STATE_SETTLING states - this state is reported whenever drawer starts moving (either opens or closes). So once you see this state - check whether drawer is opened now and act accordingly:
mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close ) { @Override public void onDrawerStateChanged(int newState) { if (newState == DrawerLayout.STATE_SETTLING) { if (!isDrawerOpen()) { // starts opening getActionBar() .setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); } else { // closing drawer getActionBar() .setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); } invalidateOptionsMenu(); } } }; mDrawerLayout.setDrawerListener(mDrawerToggle);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With