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
Up-to-date solution:
As others have suggested, the current answer is outdated and it's advised to use mDrawerLayout.addDrawerListener(). A working solution would then be:
mDrawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
@Override
public void onDrawerStateChanged(int newState) {
if (newState == DrawerLayout.STATE_SETTLING && !mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
// Drawer started opening
}
}
});
Naturally, replace GravityCompat.START with whatever identifies your drawer (layout ID or its gravity ~ location).
Also, if you want to detect when the drawer starts closing, you can simply do:
mDrawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
@Override
public void onDrawerStateChanged(int newState) {
if (newState == DrawerLayout.STATE_SETTLING) {
if (!mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
// Drawer started opening
} else {
// Drawer started closing
}
}
}
});