DrawerLayout Double Drawer (Left and Right Drawers simultaneously)
You can call it like this in a ToggleButton's handler for example :
mDrawerLayout.openDrawer(mDrawer);
mDrawerLayout.closeDrawer(mDrawer);
Where mDrawer is a reference to the specific drawer you need to open (be it a view or a layout), in your case, the actual ListView you wish to display.
Left and Right Drawers simultaneously while using fragments in DrawerLayout
Add another child to the DrawerLayout in your XML and give it android: android:layout_gravity ="right"
(or android: android:layout_gravity ="end"
if you want right-to-left support as well).
DrawerLayout Double Drawer lock right Drawer
Set the drawer mode to LOCK_MODE_LOCKED_CLOSED
.
The drawer is locked closed. The user may not open it, though the app may open it programmatically.
public void setDrawerLockMode (int lockMode, int edgeGravity)
android two navigation drawer animation
Your if
statement is not working as you expect because the root View
s in your included drawer layouts are LinearLayout
s, whereas the View
s you're finding and assigning to mLeftDrawerView
and mRightDrawerView
in your code are the ListView
s. The drawerView
in the various listener methods will be the root View
of the included drawer layouts; i.e., the LinearLayout
s. This means that drawerView == mLeftDrawerView
will never be true.
The solution is to assign IDs to the LinearLayout
in the XML, find those View
s in the code, and assign those to mLeftDrawerView
and mRightDrawerView
.
For example, your left drawer layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/leftdrawer"
...
>
<ListView
android:id="@+id/leftlistviewdrawer"
...
/>
</LinearLayout>
You would do the same with the right drawer layout. Then, in the initialization:
private void initNavigationDrawers() {
mRightDrawerView = ( LinearLayout )findViewById( R.id.rightdrawer );
mLeftDrawerView = ( LinearLayout )findViewById( R.id.leftdrawer );
mRightDrawerListView = ( ListView )findViewById( R.id.rightlistviewdrawer );
mLeftDrawerListView = ( ListView )findViewById( R.id.leftlistviewdrawer );
mDrawerLayout = ( DrawerLayout )findViewById( R.id.drawer_layout );
mRightDrawerListView.setAdapter( menuAdapter );
mLeftDrawerListView.setAdapter( menuAdapter );
initDrawerToggle();
mDrawerLayout.setDrawerListener( mDrawerToggle );
}
And you would also need to change the declared type for mLeftDrawerView
and mRightDrawerView
to LinearLayout
.
How to disable drawer layout from one side?
this may help you...
drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerStateChanged(int arg0) {
}
@Override
public void onDrawerSlide(View view, float arg1) {
}
@Override
public void onDrawerOpened(View view) {
if(view == rightDrawerView) {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, leftDrawerView);
} else if(view == leftDrawerView) {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, rightDrawerView);
}
}
@Override
public void onDrawerClosed(View view) {
if(view == rightDrawerView) {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, leftDrawerView);
} else if(view == leftDrawerView) {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, rightDrawerView);
}
}
});
Related Topics
How to Create a Resizable Rectangle with User Touch Events on Android
Creating a Directory in /Sdcard Fails
Creating Custom Lockscreen in Android
How to Downgrade Android Emulator
How to Generate an Md5 Checksum for a File in Android
How to Block a Mobile Number Call and Message Receiving in Android Application Development
Android How to Apply Mask on Imageview
How to Set a Font for the Options Menu
How to Stop Asynctask Thread in Android
Android: Can You Nest Fragments
How to Add Footer to Navigationview - Android Support Design Library
How to Find MAC Address of an Android Device Programmatically
Geocoder.Getfromlocation Throws Ioexception on Android Emulator
Setonitemclicklistener on Custom Listview
Android - Setonclicklistener VS Onclicklistener VS View.Onclicklistener
Onrequestpermissionsresult Not Being Called in Fragment If Defined in Both Fragment and Activity