2

Ich muss Navigationsmenü Elemente auf der rechten Seite ausrichten. Ich lese viele Artikel und Fragen und Antworten, aber ich konnte nicht finden, was in meinem Projekt falsch ist. Das ist mein xml:Android von rechts nach links NavigationDrawler Menüpunkte sind nicht RTL

<?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" 
tools:openDrawer="right"> 

<include 
    layout="@layout/content_activity_home" 
    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_activity_home" 
    app:menu="@menu/activity_home_drawer" /> 

Dies ist activity_home_drawer.xml:

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 

<group android:checkableBehavior="single"> 
    <item 
     android:id="@+id/menu_account" 
     android:icon="@drawable/ic_profile" 
     android:title="حساب کاربری" /> 
    <item 
     android:id="@+id/menu_logout" 
     android:icon="@drawable/ic_sign_out" 
     android:title="خروج از حساب" /> 
</group> 

ich Schublade sich von der Öffnung nach rechts machen können, aber Elemente von NavigationView noch bleibe von links nach rechts. Sie können das Ergebnis hier sehen:

enter image description here

Wie Sie Menüpunkte sind nicht von rechts nach links. Wie man sie rtl macht?

+0

Ich füge diesen Code in meine app, aber ich diese Störung erhalte: „Keine Schublade Ansicht mit der Schwerkraft LEFT gefunden“ –

+0

@ Navid_pdp11 mir Ihren Code senden, es zu beheben – Fartab

+0

ich Richtung RTL zu meiner Schublade hinzufügen und offen von rechts jetzt :) –

Antwort

6

Versuchen Sie, android: layout = "rtl"

<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" /> 

Dies funktioniert für api Level 17 oder höher. Für ältere Geräte gibt es einen Trick. In Anwendungsebene von Android-Manifest gesetzt supportRtl = "false" und in Layouts gesetzt layout_gravity = "right". Dies funktioniert ordnungsgemäß.

+0

Ja, es funktioniert. Danke @ Darwin. – Fartab

+0

Glückliche Codierung ... – darwin