0

I'm using DrawerLayout for drawer menu. I made a Right to Left Navigation menu. But here is my problem: the gravity of the menu item is on the right side. But I want the gravity of the menu item to be on the left side. I tried changing drawerlayout gravity and navigation gravity, but it doesn't work. How can I fix this issue?

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <data>
        <variable
            name="viewmodel"
            type="com.haii.quokka.main_screen.MainViewModel" />
    </data>
    <androidx.drawerlayout.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".MainActivity"
        android:layoutDirection="rtl"
        tools:openDrawer="right">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:minHeight="?attr/actionBarSize"
                android:theme="?attr/actionBarTheme">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Toolbar Title"
                    android:layout_gravity="center"
                    android:id="@+id/toolbar_title"
                    android:textStyle="bold"
                    android:textColor="@color/colorBlack"
                    android:textSize="15dp"
                    />

            </androidx.appcompat.widget.Toolbar>
        </com.google.android.material.appbar.AppBarLayout>


        <FrameLayout
            android:id="@+id/fragmentContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </FrameLayout>
    </LinearLayout>

        <com.google.android.material.navigation.NavigationView
            android:id="@+id/navigation_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="right"
            android:fitsSystemWindows="true"
            android:layoutDirection="rtl"
            app:headerLayout="@layout/nav_header"
            app:menu="@menu/main_menu" />
    </androidx.drawerlayout.widget.DrawerLayout>
</layout>
Nakx
  • 1,460
  • 1
  • 23
  • 32
Charles
  • 181
  • 1
  • 14
  • That's because of the `android:layoutDirection="rtl"` attributes you've set. Are you sure you really want those? The `android:layout_gravity="right"` attribute on the `` is all you need to move it to that side. – Mike M. Apr 26 '20 at 07:58
  • as you say, I tried removing android:layoutDirection="rtl" and changing android:layout_gravity="right" to left, but not working... – Charles Apr 26 '20 at 08:08
  • Huh? All I meant is to remove the `android:layoutDirection` attributes. If you really do want the drawer on the right side, then the `android:layout_gravity` needs to stay as you had it. – Mike M. Apr 26 '20 at 08:11
  • I tried removing layoutDirection in both drawerlayout and navigation. but the toolbar menu icon is set to left side. that's the reason of using layoutdirection ="rtl". do u know how to move the icon from right to left? – Charles Apr 26 '20 at 08:15
  • You can try putting that attribute only on the ``, as that's what's holding that menu icon, presumably. Alternatively, you can use a custom toggle class, like is shown in [this answer](https://stackoverflow.com/a/39136512). – Mike M. Apr 26 '20 at 08:19
  • thank you. I wanna one more thing. is there any way to know the default toolbar icon size? – Charles Apr 26 '20 at 08:52

0 Answers0