gpt4 book ai didi

android - 打开菜单时不显示抽屉导航图标

转载 作者:行者123 更新时间:2023-11-30 02:10:10 24 4
gpt4 key购买 nike

下面的代码是我的应用程序中带有工具栏Navigation Drawer:

    setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(true);

drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.empty, R.string.empty) {

@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu();
}

@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
invalidateOptionsMenu();
}
};

drawerLayout.setDrawerListener(drawerToggle); // Drawer Listener set to the Drawer toggle
drawerToggle.syncState();


@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig);
}

ma​​in_activity.xml

 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar" />

</LinearLayout>
<ListView
android:id="@+id/lvMenu"
android:background="@color/black"
android:layout_width="310dp"
android:layout_height="match_parent"
android:layout_gravity="left"/>
</android.support.v4.widget.DrawerLayout>

菜单可以正常显示,但是打开菜单时,菜单图标消失如下图:

enter image description here

这是正常状态:

enter image description here

有什么想法吗?

最佳答案

以下代码对我有用:

  drawerLayout.setDrawerListener(drawerToggle); // Drawer Listener set to the Drawer toggle

drawerLayout.post(new Runnable() {
@Override
public void run() {
// To display hamburger icon in toolbar
drawerToggle.syncState();
}
});

您需要将 drawerToggle.syncState(); 放在 Runnable() 中,并且只在代码中添加一次 drawerToggle.syncState(); .

希望这对您有所帮助。

关于android - 打开菜单时不显示抽屉导航图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30229710/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com