How do you make the Drawer to auto-open (instead of back auto-close) when you drag it even with a little amount? Like maybe 10% of the screen width for example, then we release our finger and the drawer will be opened. How do we can achieve it?
Asked
Active
Viewed 102 times
1 Answers
0
I'm not sure if the following is what you want to achieve. But you can try this. ("mDrawerLayout" is your DrawerLayout. "mNavigationView" is your NavigationView.)
mDrawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
boolean isOpen=false;
@Override
public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
if(slideOffset>0 && !isOpen){
mDrawerLayout.openDrawer(mNavigationView);
}
if(slideOffset==1){
isOpen=true;
}else if(slideOffset==0){
isOpen=false;
}
}
@Override
public void onDrawerOpened(@NonNull View drawerView) {
setMenuItemUnselected();
}
@Override
public void onDrawerClosed(@NonNull View drawerView) {
setMenuItemUnselected();
}
@Override
public void onDrawerStateChanged(int newState) {
}
});

maggie wan
- 74
- 4