gpt4 book ai didi

android - 为什么 isDrawerVisible 总是显示为 false

转载 作者:行者123 更新时间:2023-12-05 09:22:17 25 4
gpt4 key购买 nike

所以,我有这个

btn_menu.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {if(mDrawerLayout.isDrawerVisible(R.id.drawer_layout) == false) {
mDrawerLayout.openDrawer(mDrawerList);
Log.d("False", "" + mDrawerLayout.isDrawerOpen(R.id.drawer_layout));
} else {
mDrawerLayout.closeDrawer(mDrawerLayout);
Log.d("True", "" + mDrawerLayout.isDrawerOpen(R.id.drawer_layout));
}
}
});

在“btn_menu”上单击我将打开和关闭抽屉,问题是无论我做什么,方法“isDrawerOpen”将始终返回 false。我不知道还能做什么。

这是布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->

<ExpandableListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />

</android.support.v4.widget.DrawerLayout>

编辑:blipinsk 的回答是正确的。但是我也必须更改 if 测试。

if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
mDrawerLayout.closeDrawer(Gravity.LEFT);
} else {
mDrawerLayout.openDrawer(Gravity.LEFT);
}

最佳答案

当您调用 isDrawerOpen 时,您需要指定要检查的抽屉(可以有两个 - 一个在右边,一个在左边)。

所以在你的情况下应该是:

mDrawerLayout.isDrawerOpen(Gravity.LEFT)

关于android - 为什么 isDrawerVisible 总是显示为 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28046187/

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