Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android right to left NavigationDrawer menu items aren't RTL

I need to align navigation menu items to the right. I read many articles and questions and answers but i couldn't find what's wrong in my project. This is my xml:

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

This is 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>

I can make drawer itself to open from right but elements of NavigationView still remain left to right. You can see the result here:

enter image description here

As you see menu items aren't right to left. How to make them rtl?

like image 717
Fartab Avatar asked Aug 09 '16 10:08

Fartab


People also ask

How do I change my navigation drawer to open from right to left?

set DrawerLayout tools:openDrawer="end" set NavigationView android:layout_gravity="end" change tag view from androidx.

How do I get navigation drawer in all activity?

The user can view the navigation drawer when they swipe the activity's screen from the left edge of the android device. A user can also find it from the activity, by tapping the app icon (also known as the “hamburger” menu) in the action bar.

What is Android drawer layout?

DrawerLayout acts as a top-level container for window content that allows for interactive "drawer" views to be pulled out from one or both vertical edges of the window.

What is navigation drawer activity in Android?

The navigation drawer is a UI panel that shows your app's main navigation menu. The drawer appears when the user touches the drawer icon in the app bar or when the user swipes a finger from the left edge of the screen.


1 Answers

try adding android:layoutDirection="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" />

This works for api level 17 or above. For older devices there is a trick. In application level of android manifest set supportRtl="false" and in layouts set layout_gravity="right". This works properly.

like image 68
darwin Avatar answered Oct 26 '22 23:10

darwin