1

sorry for my bad English. I have a navigation drawer in some activities, I want the icon of each navigation view item to be placed to the right of that item's text and the whole item get right gravity. Because I only used Persian in my app, I can not use "supportsRtl" in my code, if I use, it will look weird when I set device language to any rtl languages.

I think probably I can fix this with setting custom layout for navigation view, but I'm looking for a simpler way. this is my NavigationView XML code:

<android.support.design.widget.NavigationView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:menu="@menu/menu"
    android:layout_gravity="end" />

enter image description here

enter image description here

Edited :
layoutDirection is a good answer but i used
drawerLayout.openDrawer(GravityCompat.START);
for opening navigation drawer. now if device language be an rtl language this make app crash.

danial abadi ghadim
  • 395
  • 1
  • 3
  • 10

2 Answers2

2

Make supportsRtl true and set the layout dirction to RTL on navigation View and LTR in other layouts

Billel Arfi
  • 73
  • 10
  • layout direction is a good answer but i used drawerLayout.openDrawer(GravityCompat.START); for opening navigation drawer. now if device language be an rtl language this make app crash. can i handle it with some solution? – danial abadi ghadim Jan 03 '19 at 10:43
  • thanks for your answer, i used gravityCompat.start but i must use Gravity.Right instead. – danial abadi ghadim Jan 03 '19 at 11:25
2

Just add android:layoutDirection="rtl" to your NavigationView, like this:

<android.support.design.widget.NavigationView
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     app:menu="@menu/menu"
     android:layoutDirection="rtl"
     android:layout_gravity="end" /> 
Denysole
  • 3,903
  • 1
  • 20
  • 28