Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right to left menu items Android in NavigationView

im beginer of android. i design a navigation drawer like this: enter image description here

as you see all items in menu are on the right Except "SubHeader".

how can i move "SubHeader" item to the right of this menu? i use all properties like gravity, layout gravity, layoutDirection to the SubHeaderItem but it doesn't work.

my code is

 <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/navigation_view"
        android:layout_gravity="end"
        android:fitsSystemWindows="true"
        android:layoutDirection="rtl"
        app:headerLayout="@layout/navigation_header"
        app:menu="@menu/navigation_menu"
        />

my menu code is:

<menu xmlns:android="http://schemas.android.com/apk/res/android"    >
    <group android:checkableBehavior="single">
        <item
            android:title="inbox"
            android:id="@+id/inbox_id"
            android:icon="@drawable/inbox" />
    </group>
    <item android:title="SubHeader">

        <menu>
            <item
                android:title="all main"
                android:id="@+id/all_mail"
                android:icon="@drawable/allmail" />
        </menu>
    </item>

</menu>
like image 745
hossein derakhshan Avatar asked Dec 13 '22 21:12

hossein derakhshan


1 Answers

Try adding these attributes to NavigationView in your layout file.

android:layoutDirection="rtl"
android:textDirection="rtl"

If no other way. You should use custom layout

example:

<android.support.design.widget.NavigationView
  android:layoutDirection="rtl"
  android:id="@+id/navigation_view"
  android:layout_width="wrap_content"
  android:layout_height="match_parent"
  android:layout_gravity="right"
  android:fitsSystemWindows="true"
  app:headerLayout="@layout/nav_header_main"
  app:menu="@menu/activity_main_drawer>
 <LinearLayout>
 // code xml here
 </LinearLayout>
 <android.support.design.widget.NavigationView/>
like image 153
Nguyễn Trung Hiếu Avatar answered Dec 24 '22 08:12

Nguyễn Trung Hiếu