汉堡菜单旋转到新活动上的箭头 [英] Hamburger menu spin to arrow on new activity

查看:112
本文介绍了汉堡菜单旋转到新活动上的箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,随着Android的最新Gmail更新,当您单击其中一封电子邮件时,会打开一个新的活动"(由于后退箭头,我认为它不是片段).

但是,新活动的后退箭头并不像默认情况下那样出现.主界面中的汉堡菜单会变成动画中的箭头(请参见此处的视频: http://www.androidpolice.com/2014/10/30/google-turns-design-inconsistency-ten-latest-round-navigation-drawers/).但是,我想知道在创建新的片段/活动时是否可以使用相同的动画,无论Gmail可能使用哪种方式.

解决方案

为时已晚,但我将其放在此处以解决即将出现的问题. Gmail应用会按段打开电子邮件.因为您仍然可以在此页面中使用汉堡菜单.将汉堡菜单图标更改为后退按钮我使用了此代码,因此效果很好.

  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是ActionBarDrawerToggle的实例,您可以在活动中使用此代码对其进行初始化

toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

reverseToolbar在用户单击时将工具栏的后图标更改为汉堡菜单图标.在您的活动中声明此方法,并替换片段中的图标,然后将此代码添加到片段中. (((YourActivity)getActivity()).setupToolbarNavigation

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.

解决方案

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

这篇关于汉堡菜单旋转到新活动上的箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆