So, I have this
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));
}
}
});
On the "btn_menu" click I will open and close the drawer, thing is that no matter what I do the method "isDrawerOpen" will ALWAYS return false. I don't know what else to do.
Here is the layout:
<?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>
Edit: blipinsk answer was right. But I had to change the if test too.
if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
mDrawerLayout.closeDrawer(Gravity.LEFT);
} else {
mDrawerLayout.openDrawer(Gravity.LEFT);
}
When you call isDrawerOpen
you need to specify which drawer (there can be two - one on the right and one on the left) you are trying to check.
So in your case it should be:
mDrawerLayout.isDrawerOpen(Gravity.LEFT)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments