I'm using Navigation Drawer
in my application.
When the user clicks on any of the menu item in drawer, it opens a new Activity
(not fragment).
Now, I'm using slide_right_in/slide_left_out animation
as transition between activities.
The code works, but these animations conflicts with the closing animation of Navigation Drawer, as even before the drawer gets completely closed, the current activity starts sliding out to left & next activity starts sliding in from right.
So, is there any way to start the animation only after drawer is completely closed?
Thank You
Every answer is so complicated..... It's so easy.
Just add a drawerlistener and do something in onClosed() method:
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
when you select a item from navigation drawer you will call this method to close the drawer:
drawer.closeDrawer(GravityCompat.START);
after the above method call just add below lines and do whatever you want:
drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
}
@Override
public void onDrawerOpened(@NonNull View drawerView) {
}
@Override
public void onDrawerClosed(@NonNull View drawerView) {
startActivity(finalIntent);
// Or else do something here....
}
@Override
public void onDrawerStateChanged(int newState) {
}
});
I did this somehow similiar to Jan.
If an item gets clicked, i save its id and close the Drawer:
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener()
{
@Override
public boolean onNavigationItemSelected(MenuItem menuItem)
{
clickedItem = menuItem.getItemId();
drawerLayout.closeDrawers();
return true;
}
});
If the Drawer gets closed i listen for it and check if an item has been clicked. If it has i call my method to handle the navigation click.
drawerToggle = new ActionBarDrawerToggle(activity, drawerLayout, R.string.accessibility_open_nav, R.string.accessibility_open_nav)
{
@Override
public void onDrawerClosed(View drawerView)
{
super.onDrawerClosed(drawerView);
if(clickedItem != 0)
{
handleNavigationClick();
}
}
};
drawerLayout.setDrawerListener(drawerToggle);
Here i react to the item click on open intents in this case (simplified). You need to reset the clickedItem here to 0. That is, because if you go back to an activity, open and close the drawer, it would still have the clickedItem number and would handle the click again.
private void handleItemClick()
{
switch (clickedItem)
{
case R.id.item_1:
do_something_1;
break;
case R.id.item_2:
do_something_2;
break;
}
clickedItem = 0;
}
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