从右到左对齐工具栏图标?

Caf*_*tte 12 android android-toolbar

在我的应用程序中,我实现了一些语言,包括从右到左开始的阿拉伯语.我想对齐工具栏中的所有图标RIGHT_TO_LEFT.

我试着layout_gravity="right"gravity="right"但没有发梗.

我的工具栏代码:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/primary_color"
    app:popupTheme="@style/Theme.AppCompat.Light"/>
Run Code Online (Sandbox Code Playgroud)

这就是我想要的:


Jen*_*the 21

Android 4.2(API级别17)引入了官方的从右到左的支持,因此只有在最低SDK级别为17时才会有效:

1)将android:supportsRtl="true"属性放在AndroidManifest文件中以支持从右到左的布局方向.

2)其次将此代码放在您的活动的onCreate()方法中:

if (getWindow().getDecorView().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR){
            getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
        }
Run Code Online (Sandbox Code Playgroud)

如果系统使用相应的语言,这将使您的所有内容从右到左放置.在设置填充时,还要确保使用开始/结束而不是左/右,以确保所有元素都正确对齐.

有关官方支持声明的更多信息,请访问:http://android-developers.blogspot.be/2013/03/native-rtl-support-in-android-42.html


M K*_*imi 5

将 android:supportsRtl="true" 属性放入 AndroidManifest 文件中。之后,将以下行添加到工具栏标记中:

android:layoutDirection="rtl"
Run Code Online (Sandbox Code Playgroud)