问题
I've noticed that with the more recent Gmail updates for Android, when you click on one of your emails, a new Activity opens (I'm assuming it's not a fragment because of the back arrow).
The new activity's back arrow does not just appear as they do by default, however. The hamburger menu from the main interface spins into an arrow in an animation (see the video here: http://material-design.storage.googleapis.com/publish/material_v_3/material_ext_publish/0B3T7oTWa3HiFbFRfT196SWRyS2s/animation_delightfuldetails_wellcrafted.webm)
(Note: The newly opened email MAY be a fragment, because the toolbar doesn't change & the default new activity animation doesn't play. I'm not sure which one it is.)
Clarification: I do know how to get the hamburger menu to turn into an arrow when it's pressed/when the navigation drawer is opened. In fact, I purposefully disabled said animation because it goes against specs. (see this article: http://www.androidpolice.com/2014/10/30/google-turns-design-inconsistency-ten-latest-round-navigation-drawers/). I want to know, however, if the same animation is possible when creating a new fragment/activity, whichever one Gmail probably uses.
回答1:
If you use android.support.v7.app.ActionBarDrawerToggle
it animates automatically.
回答2:
It too late but i put it here for upcoming questions. Gmail app opens email in a fragment.Cause you can still use hamburger menu in this page.Changing hamburger menu icon to back button i use this code and it works fine.
public void setupToolbarNavigation() {
toggle.setDrawerIndicatorEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
toggle.setToolbarNavigationClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
reverseToolbar();
}
});
}
public void reverseToolbar() {
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);
toggle.setDrawerIndicatorEnabled(true);
toggle.setToolbarNavigationClickListener(null);
}
toggle is instance of ActionBarDrawerToggle which you can initiate it with this code in your activity
toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
reverseToolbar change toolbar back icon to hamburger menu icon when user clicked.Declare this method in your activity and for replacing icon in fragment put this code to your fragment. ((YourActivity)getActivity()).setupToolbarNavigation
来源:https://stackoverflow.com/questions/29775234/hamburger-menu-spin-to-arrow-on-new-activity