Toolbar Toolbar Functionality

I have a problem with the toolbar and the back button. Here are the settings I have:

enter image description here

When I add a part fragment, I animate the hamburger on the toolbar as described here , and this makes the hamburger animate the arrow.

Even in the comments section, the user mentions:

It works great. Just set start = 0 and end = 1 to go from the hamburger to the arrow, and start = 1 and end = 0 for the arrow to the hamburger. One thing you will have to keep track of when the drawer is closed when the arrow is shown. At this point, the hamburger ends with a show (due to a drawer slide) that you will have to fix.

But I can’t figure out how to properly set the back arrow. When I press the back arrow, the drawer opens and a part fragment does not appear. How do I implement this?

Questions

  • How should I animate a hamburger with the back of an arrow when adding a fragment of a part? assuming a related solution is not enough.
  • How to override the back arrow to perform only certain functions that I want? how to revive a hamburger, pop back the stack and DO NOT open the box.
+8
android android-toolbar
source share
2 answers

After several hours of searching and playing, I was able to create a solution that ran for each requirement. Sources: 1 , 2

detailFragmentActive = false; @Override protected void onCreate(Bundle savedInstanceState) { setSupportActionBar(mToolbar); ... mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(detailFragmentActive) { onBackPressed(); //if(displayBackAgain) //return; //return after so you don't call syncState(); }else if (mDrawerLayou.isDrawerOpen(GravityCompat.START)) mDrawerLayout.closeDrawer(GravityCompat.START); else mDrawerLayout.openDrawer(GravityCompat.START); mDrawerToggle.syncState(); } }); } private void animateHamburger(boolean isArrow){ int start = 0, end = 1; if(isArrow){ detailFragmentActive = false; start = 1; end = 0; mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); }else{ detailFragmentActive = true; mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } ValueAnimator anim = ValueAnimator.ofFloat(start, end); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float slideOffset = (Float) valueAnimator.getAnimatedValue(); mDrawerToggle.onDrawerSlide(mDrawerLayout, slideOffset); } }); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(500); anim.start(); } @Override public void onBackPressed() { super.onBackPressed(); animateHamburger(true); } public void onFragmentChange(){ ... animateHamburger(false); } 
+2
source share

You can set a listener for this button:

 toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (flagDeterminingAction) { drawerLayout.openDrawer(drawerListView); } else { onBackPressed(); //or popbackstack or whatever you are using to going back in navigation } } 
0
source share

All Articles