I want use two DrawerLayouts in one Activity. One of them opens on the left side and the other of them opens on the right side. They should open after a click on the ToolBar.
For example : if I click the left button on the ToolBar, it opens the left DrawerLayout and if click the right button on the ToolBar, it opens the right DrawerLayout.
Please see these images to understand my meaning.
my XML code :
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/search_hint"
tools:context=".Main_Page">
<include
android:id="@+id/app_bar"
layout="@layout/app_toolbar" />
<com.ogaclejapan.smarttablayout.SmartTabLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/viewpagertab"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/app_bar"
android:background="@color/primaryColor"
android:clipToPadding="true"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:stl_defaultTabTextColor="@color/search_hint"
app:stl_defaultTabTextHorizontalPadding="18dp"
app:stl_defaultTabTextSize="15sp"
app:stl_distributeEvenly="true"
app:stl_dividerColor="@color/transparent"
app:stl_dividerThickness="0dp"
app:stl_indicatorColor="@color/black_20"
app:stl_indicatorCornerRadius="18dp"
app:stl_indicatorGravity="center"
app:stl_indicatorInterpolation="smart"
app:stl_indicatorThickness="36dp"
app:stl_underlineColor="@color/transparent"
app:stl_underlineThickness="0dp" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/viewpagertab">
</android.support.v4.view.ViewPager>
<co.aenterhy.toggleswitch.ToggleSwitchButton
android:id="@+id/toggle"
style="@style/ToggleSwitchButton" />
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/main_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/menu_main__page"
app:headerLayout="@layout/header_drawer_main"
app:itemTextColor="@color/primaryColor"
app:itemIconTint="@color/primaryColor"/>
</android.support.v4.widget.DrawerLayout>
java code :
toolbar = (Toolbar) findViewById(R.id.app_bar);
TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
mTitle.setText("title");
Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);
mNaviView = (NavigationView) findViewById(R.id.main_drawer);
mNaviView.setNavigationItemSelectedListener(this);
mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.openDrawer, R.string.closeDrawer) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (con.isOnline()) {
new get_menu_info().execute(public_username);
}
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
};
Drawer.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
ImageView e1 = (ImageView) toolbar.findViewById(R.id.right_tool);
e1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Drawer.openDrawer(Gravity.RIGHT);
}
});
LogCot Error :
10-15 10:44:31.130 7061-7061/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.tellfa.smsbox, PID: 7061
java.lang.IllegalArgumentException: No drawer view found with gravity RIGHT
at android.support.v4.widget.DrawerLayout.openDrawer(DrawerLayout.java:1322)
at com.tellfa.smsbox.activities.Main_Page$5.onClick(Main_Page.java:210)
at android.view.View.performClick(View.java:4764)
at android.view.View$PerformClick.run(View.java:19844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5349)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)

