how to change menu item gravity to right in Naviga

2019-05-10 09:06发布

问题:

I need to put a menu item icon at right of text (by default it's on the left side) so how to change menu item gravity to right in NavigationView ?

because we can not custom NavigationView Items,I think it's impossible. can any one help me.

my menu xml file is:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:id="@+id/menu_group_2">
        <item
            android:id="@+id/menu_settings"
            android:title="Settings" />
        <item
            android:id="@+id/menu_about"
            android:title="About" />
    </group>
</menu>

and my navigationview in layout is

<android.support.design.widget.NavigationView
    android:id="@+id/vNavigation"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:background="#ffffff"
    app:headerLayout="@layout/view_global_menu_header"
    app:itemIconTint="#8b8b8b"
    app:itemTextColor="#666666"
    android:gravity="right"
    app:menu="@menu/drawer_menu" />

回答1:

try this: change Navigation layout gravity to:

android:layout_gravity="start"


回答2:

add to your Activity before setContentView(R.layout.YOUR_LAYOUT);

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}