Ali Esmaeili
Ali Esmaeili

Reputation: 542

Right to left menu items Android

I have an Slide menu as picture one. And i need to align its items title to be right to left like slide two . I tried gravity=right but didn't work.

Here is my code :

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:gravity="end"
    android:layout_gravity="end">

    <group android:checkableBehavior="single"
        android:layout_gravity="end"
        android:gravity="end">

        <item
            android:id="@+id/nav_1"
            android:icon="@drawable/ic_keyboard_arrow_left_24dp"
            android:gravity="end"
            android:layout_gravity="end"
            android:title="آگهی خود را ثبت کنید"/>

</menu>

enter image description here

The desired menu will be :

enter image description here

Upvotes: 9

Views: 14404

Answers (4)

Hamed samsami
Hamed samsami

Reputation: 11

in res>values>styles add bellow item : rtl

and then in toolbar or your navigation menu XML tag add: android:textDirection="rtl" android:layoutDirection="ltr"

Upvotes: 0

Ali.Rashidi
Ali.Rashidi

Reputation: 1462

if you are going to change your Menu direction which is inside a DrawerLayout just add

android:layoutDirection="rtl"

to your NavigationView element. output should be like:

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:fitsSystemWindows="true"
    android:layoutDirection="rtl"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

Upvotes: 3

Omri Lugasi
Omri Lugasi

Reputation: 327

To create right to left menu you just need to add android:layoutDirection="rtl" to the menu tag


android:layoutDirection="rtl"


<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:gravity="end"
    android:layoutDirection="rtl"
    android:layout_gravity="end">

    <group android:checkableBehavior="single"
        android:layout_gravity="end"
        android:gravity="end">

        <item
            android:id="@+id/nav_1"
            android:icon="@drawable/ic_keyboard_arrow_left_24dp"
            android:gravity="end"
            android:layout_gravity="end"
            android:title="آگهی خود را ثبت کنید"/>
    </group>
</menu>

you can see here the source:

http://developer.android.com/reference/android/util/LayoutDirection.html#LTR

api 17 and above

Upvotes: 10

Pooyan Nayyeri
Pooyan Nayyeri

Reputation: 11

The layoutDirection attribute should be added to the parent activity layout XML:

android:layoutDirection="rtl"

Upvotes: 1

Related Questions