调用ActionBarDrawerToggle.setDrawerIndicatorEnabled(false)后不显示向上箭头 [英] Up arrow does not show after calling ActionBarDrawerToggle.setDrawerIndicatorEnabled(false)

查看:163
本文介绍了调用ActionBarDrawerToggle.setDrawerIndicatorEnabled(false)后不显示向上箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说明了一切.当我调用mDrawerToggle.setDrawerIndicatorEnabled(false)时,我不希望显示"hamburger"图标,而是要向后导航箭头.

The title says it all. When I call the mDrawerToggle.setDrawerIndicatorEnabled(false) I don't want the "hamburger" icon to be shown anymore but the backwards navigation arrow.

不幸的是,当我调用此方法时,仅显示标题而没有向后箭头或汉堡"图标.再次将drawerIndicatorEnabled设置为true后,它将再次显示汉堡"图标.

Unfortunately when I call this method just the title is shown without the backwards arrow nor the "hamburger" icon. After setting the drawerIndicatorEnabled to be true again it shows the "hamburger" icon again.

我设置了getSupportActionBar().setDisplayHomeAsUpEnabled(true)getSupportActionBar().setDisplayShowHomeEnabled(true)

基本上是这里建议的解决方案:将抽屉图标更改为后退箭头不知何故不给我后退箭头.

Basically the solution suggested here: Change drawer icon back to back arrow somehow doesn't give me the back arrow.

有人知道这个问题的解决方案吗?非常感谢你!

Does anyone know a solution for this issue? Thank you very much!

推荐答案

经过数小时的试验和错误,我想出了一个解决方案,可以从汉堡"切换为箭头",然后再返回. 这是很奇怪和不自然的,不要问我为什么以这种方式起作用,但是它可以起作用.此外,这是唯一允许我执行此操作的解决方案,

After hours of trials and errors I came up with a solution that allows to switch from "hamburger" to "arrow" and back. This is very weird and unnatural, don't ask me why it works in this way, but it works. Furthermore, this is the only solution that allowed me to do this, nothing else worked.

我只有一项活动有片段.当我从一个片段切换到另一个片段时,我在活动displayingInnerFragment中设置了布尔变量.对于那些片段,在displayingInnerFragment == true处,我在左上角显示箭头",对于其他所有片段,我显示汉堡".在切换到任何片段之前,我执行以下代码:

I have only one activity with fragments. When I'm switching from one fragment to another, I'm setting boolean variable in my activity displayingInnerFragment. For those fragments, where displayingInnerFragment == true, I show "arrow" in the top left corner, and for all others I show "hamburger". The following code I execute before switching to any fragment:

    ActionBar actionBar = getSupportActionBar();
    if (displayingInnerFragment) {
        actionBar.setDisplayHomeAsUpEnabled(false);
        drawerToggle.setDrawerIndicatorEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);
    } else {
        drawerToggle.setDrawerIndicatorEnabled(true);
    }

请注意在一个分支中两次调用actionBar.setDisplayHomeAsUpEnabled().这是drawerToggle.setDrawerIndicatorEnabled(false)工作所必需的.否则它将无法正常工作.所有其他选项要么一时不显示箭头",要么不隐藏箭头"或汉堡包".

Note the double call to actionBar.setDisplayHomeAsUpEnabled() in one branch. This is required for drawerToggle.setDrawerIndicatorEnabled(false) to work. Otherwise it will not work properly. All other options either don't show "arrow" or hide "arrow" or "hamburger" at one moment or another.

这篇关于调用ActionBarDrawerToggle.setDrawerIndicatorEnabled(false)后不显示向上箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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