简体   繁体   English

默认的Android Studio导航抽屉活动模板不显示汉堡图标,仅显示箭头图标

[英]Default Android Studio Navigation Drawer Activity Template does not show Hamburger Icon, only arrow icon

This person is basically running into the same problem I'm having , however, the provided solution is not helpful, nor does it work for me since my code is in fact calling mDrawerToggle.sycnState() (in a deferred Runnable). 这个人基本上遇到了我遇到的同样的问题 ,但是,提供的解决方案没有帮助,也不适用于我,因为我的代码实际上是调用mDrawerToggle.sycnState()(在延迟的Runnable中)。

I've also tried adding it to onActivityCreated in my Fragment, which doesn't seem to do anything. 我也尝试将它添加到我的片段中的onActivityCreated,它似乎没有做任何事情。 Not knowing exactly what syncState does, I can't tell if it's syncing the state of being open (which the template code makes happen by default), and then it never is synced again when the drawer is manually closed. 不知道究竟是什么syncState做什么,我无法判断它是否正在同步打开状态(模板代码默认发生),然后在手动关闭抽屉时它永远不会再次同步。

I'd post code but you can test this by making a new project in Android Studio (1.2.2), selecting the Navigation Drawer Activity, and then simply running the project - no changes necessary. 我发布了代码但您可以通过在Android Studio(1.2.2)中创建一个新项目,选择导航抽屉活动,然后只是运行项目来测试这一点 - 无需进行任何更改。 You'll see that the only icon is ever the <- arrow. 你会看到唯一的图标是< - 箭头。 I've even set breakpoints to inspect the ActionBarDrawerToggle object which in fact has the hamburger icon in its memory for the icon to draw, flummoxing me even more! 我甚至设置了断点来检查ActionBarDrawerToggle对象,该对象实际上在其内存中有汉堡图标,用于绘制图标,让我更加惊慌!

I'm at my wits end here. 我在这里结束了我的智慧。

I just figured out a solution in case anyone else is having this problem: 我刚刚想出了一个解决方案,以防其他人遇到这个问题:

Change the import at the top of the fragment from 更改片段顶部的导入

import android.support.v4.app.ActionBarDrawerToggle;

to

import android.support.v7.app.ActionBarDrawerToggle;

then change the code in setUp from 然后更改setUp中的代码

mDrawerToggle = new ActionBarDrawerToggle(
            getActivity(),                    /* host Activity */
            mDrawerLayout,                    /* DrawerLayout object */
            R.drawable.ic_drawer,             /* nav drawer image to replace 'Up' caret */
            R.string.navigation_drawer_open,  /* "open drawer" description for accessibility */
            R.string.navigation_drawer_close  /* "close drawer" description for accessibility */
    )

to

mDrawerToggle = new ActionBarDrawerToggle(
            getActivity(),                    /* host Activity */
            mDrawerLayout,                    /* DrawerLayout object */
            R.string.navigation_drawer_open,  /* "open drawer" description for accessibility */
            R.string.navigation_drawer_close  /* "close drawer" description for accessibility */
    )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM