更改菜单项 (DrawerLayout) 的图标方向 Android?
change the icons direction for menu items(DrawerLayout) Android?
如何更改项目方向菜单?
我需要将图标方向更改为 RTL 而不是 LTR,我使用 Gravity
和 Layout_Gravity
但不起作用。
我能做什么?下面是我的 XML :
menu_start.xml :
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_home"
android:icon="@drawable/circle"
android:title="@string/Search" />
<item
android:id="@+id/nav_example_item_1"
android:icon="@drawable/circle"
android:title="Example Item #1" />
</group>
<item android:title="Sub items">
<menu>
<item
android:id="@+id/nav_example_sub_item_1"
android:title="Example Sub Item #1" />
</menu>
</item>
</menu>
activity_start.xml :
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/KeepToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- We use a Toolbar so that our drawer can be displayed
in front of the action bar -->
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar_Start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ORANGE_700">
<ImageView
android:id="@+id/drawer_indicator"
android:layout_width="30dp"
android:layout_height="30dp" />
</android.support.v7.widget.Toolbar>
<!-- The rest of your content view -->
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/KeepToolbar"
android:orientation="vertical">
<ViewFlipper
android:id="@+id/viewflipper"
android:layout_width="match_parent"
android:layout_height="150dp"
android:autoStart="true"
android:background="@color/ORANGE_700"
android:inAnimation="@anim/right_in"
android:outAnimation="@anim/left_out">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/a" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/b" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/c" />
</ViewFlipper>
<android.support.v7.widget.RecyclerView
android:id="@+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="1dp"
android:scrollbarDefaultDelayBeforeFade="5000"
android:scrollbarFadeDuration="5000"
android:scrollbars="vertical" />
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@drawable/background_color"
app:headerLayout="@layout/header_drawer"
app:menu="@menu/menu_start" />
</android.support.v4.widget.DrawerLayout>
试试这个:首先将 { android:supportsRtl="true" }
添加到 AndroidManifest.xml
:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:supportsRtl="true" >
</application>
然后在您的 activity_start.xml
中将这两行添加到 DrawerLayout :
android:layoutDirection="rtl"
android:textDirection="anyRtl"
如何更改项目方向菜单?
我需要将图标方向更改为 RTL 而不是 LTR,我使用 Gravity
和 Layout_Gravity
但不起作用。
我能做什么?下面是我的 XML :
menu_start.xml :
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_home"
android:icon="@drawable/circle"
android:title="@string/Search" />
<item
android:id="@+id/nav_example_item_1"
android:icon="@drawable/circle"
android:title="Example Item #1" />
</group>
<item android:title="Sub items">
<menu>
<item
android:id="@+id/nav_example_sub_item_1"
android:title="Example Sub Item #1" />
</menu>
</item>
</menu>
activity_start.xml :
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/KeepToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- We use a Toolbar so that our drawer can be displayed
in front of the action bar -->
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar_Start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ORANGE_700">
<ImageView
android:id="@+id/drawer_indicator"
android:layout_width="30dp"
android:layout_height="30dp" />
</android.support.v7.widget.Toolbar>
<!-- The rest of your content view -->
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/KeepToolbar"
android:orientation="vertical">
<ViewFlipper
android:id="@+id/viewflipper"
android:layout_width="match_parent"
android:layout_height="150dp"
android:autoStart="true"
android:background="@color/ORANGE_700"
android:inAnimation="@anim/right_in"
android:outAnimation="@anim/left_out">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/a" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/b" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/c" />
</ViewFlipper>
<android.support.v7.widget.RecyclerView
android:id="@+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="1dp"
android:scrollbarDefaultDelayBeforeFade="5000"
android:scrollbarFadeDuration="5000"
android:scrollbars="vertical" />
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@drawable/background_color"
app:headerLayout="@layout/header_drawer"
app:menu="@menu/menu_start" />
</android.support.v4.widget.DrawerLayout>
试试这个:首先将 { android:supportsRtl="true" }
添加到 AndroidManifest.xml
:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:supportsRtl="true" >
</application>
然后在您的 activity_start.xml
中将这两行添加到 DrawerLayout :
android:layoutDirection="rtl"
android:textDirection="anyRtl"