android - make a navigation drawer with right gravity -


i'm trying make app navigaton bar... activity layout:

<?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:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitssystemwindows="true" android:layout_gravity="right" tools:opendrawer="right">  <include     layout="@layout/app_bar_navigation"     android:layout_width="match_parent"     android:layout_height="match_parent" />  <android.support.design.widget.navigationview     android:id="@+id/nav_view"     android:layout_width="wrap_content"     android:layout_height="match_parent"     android:layout_gravity="right"     android:fitssystemwindows="true"     app:headerlayout="@layout/nav_header_navigation"     app:menu="@menu/activity_navigation_drawer" />   </android.support.v4.widget.drawerlayout> 

and coordinator layout witch contains toolbar:

<android.support.design.widget.appbarlayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:theme="@style/apptheme.appbaroverlay">      <android.support.v7.widget.toolbar         android:id="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="?attr/actionbarsize"         android:background="?attr/colorprimary"         app:popuptheme="@style/apptheme.popupoverlay" />   </android.support.design.widget.appbarlayout>  <include layout="@layout/content_navigation" />  <android.support.design.widget.floatingactionbutton     android:id="@+id/fab"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="bottom|start"     android:layout_margin="@dimen/fab_margin"     android:src="@android:drawable/ic_dialog_email" />  </android.support.design.widget.coordinatorlayout> 

navigation works fine when clicking on actionbardrawertoggle error comes , app cashes:

java.lang.illegalargumentexception: no drawer view found gravity left

and action of toggle button :

     drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);     actionbardrawertoggle toggle = new actionbardrawertoggle(             this, drawer, toolbar, r.string.navigation_drawer_open, r.string.navigation_drawer_close);     drawer.setdrawerlistener(toggle);     toggle.syncstate(); 

and im getting notification :

method invocation drawer.setdrawerlistener(toggle) may produce java.lang.nullpointerexeption

according documentation

to use drawerlayout, position primary content view first child width , height of match_parent. add drawers child views after main content view , set layout_gravity appropriately. drawers commonly use match_parent height fixed width.

when use include following view

<include     layout="@layout/app_bar_navigation"     android:layout_width="match_parent"     android:layout_height="match_parent" /> 

you including 2 views, makes total of 3 views.
enclose layout within linearlayout combine 2 views inside 1.

<linearlayout     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical">      <android.support.design.widget.appbarlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:theme="@style/apptheme.appbaroverlay">          <android.support.v7.widget.toolbar             android:id="@+id/toolbar"             android:layout_width="match_parent"             android:layout_height="?attr/actionbarsize"             android:background="?attr/colorprimary"             app:popuptheme="@style/apptheme.popupoverlay" />       </android.support.design.widget.appbarlayout>      <include layout="@layout/content_navigation" />      <android.support.design.widget.floatingactionbutton         android:id="@+id/fab"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="bottom|start"         android:layout_margin="@dimen/fab_margin"         android:src="@android:drawable/ic_dialog_email" />      </android.support.design.widget.coordinatorlayout>  </linearlayout> 

Comments