activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <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:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/drawerLayout" android:layout_gravity="start" android:fitsSystemWindows="true" tools:openDrawer="end" tools:context="ir.mhdr.bmi.MainActivity"> <!--Content--> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/toolbar_layout" android:layout_width="match_parent" android:layout_height="wrap_content" /> <RelativeLayout android:id="@+id/relativeLayoutMainContainer" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.BottomNavigationView android:id="@+id/bottomNavigationView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" app:itemBackground="@color/colorBottomNavigation" app:menu="@menu/bottom_navigation"> </android.support.design.widget.BottomNavigationView> </RelativeLayout> </RelativeLayout> <!--Drawer--> <android.support.design.widget.NavigationView android:id="@+id/navigationView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="end"> </android.support.design.widget.NavigationView> </android.support.v4.widget.DrawerLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity { DrawerLayout drawerLayout; Toolbar toolbar; ActionBarDrawerToggle actionBarDrawerToggle; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ViewCompat.setLayoutDirection(toolbar, ViewCompat.LAYOUT_DIRECTION_RTL); getSupportActionBar().setTitle(R.string.app_name_fa); drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close); drawerLayout.addDrawerListener(actionBarDrawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); } @Override protected void onPostCreate(@Nullable Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); actionBarDrawerToggle.syncState(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); actionBarDrawerToggle.onConfigurationChanged(newConfig); } @Override public boolean onOptionsItemSelected(MenuItem item) { // it will not work for right to left navigation drawer /* if (actionBarDrawerToggle.onOptionsItemSelected(item)) { return true; }*/ // so we have to open and close the navigation drawer ourselves if(item.getItemId() == android.R.id.home) { if(drawerLayout.isDrawerOpen(Gravity.END)) { drawerLayout.closeDrawer(Gravity.END); } else { drawerLayout.openDrawer(Gravity.END); } return true; } return super.onOptionsItemSelected(item); } }
References
https://github.com/mhdr/AndroidSamples/tree/master/065