how to change menu item gravity to right in NavigationView

被刻印的时光 ゝ 提交于 2019-12-07 17:35:24

问题


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);
}


来源:https://stackoverflow.com/questions/32613437/how-to-change-menu-item-gravity-to-right-in-navigationview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!