Hamburger menu spin to arrow on new activity

隐身守侯 提交于 2019-12-03 07:26:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!