从右到左对齐工具栏图标?
Align Toolbar icons from right to left?
在我的应用程序中,我实现了一些语言,包括从右到左开始的阿拉伯语。我想将工具栏中的所有图标对齐 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"/>
这是我想要的:
Android 4.2(API 级别 17)引入了官方的从右到左支持,因此只有当您的最低 SDK 级别为 17 时才有效:
1) 将 android:supportsRtl="true"
属性放入您的 AndroidManifest 文件中以支持从右到左的布局方向。
2) 其次将此代码放入 activity 的 onCreate() 方法中:
if (getWindow().getDecorView().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR){
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
如果系统使用相应的语言,这将使您的所有内容从右到左放置。还要确保在设置填充时使用 start/end 而不是 left/right 以确保所有元素都正确对齐。
更多官方支持公告:http://android-developers.blogspot.be/2013/03/native-rtl-support-in-android-42.html
将 android:supportsRtl="true" 属性放入您的 AndroidManifest 文件中。
之后将以下行添加到您的工具栏标签:
android:layoutDirection="rtl"
对于那些希望右侧只有汉堡包图标并且工具栏中只有图标的用户,您可以使用
android:layoutDirection="rtl"
在工具栏标签上
在我的应用程序中,我实现了一些语言,包括从右到左开始的阿拉伯语。我想将工具栏中的所有图标对齐 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"/>
这是我想要的:
Android 4.2(API 级别 17)引入了官方的从右到左支持,因此只有当您的最低 SDK 级别为 17 时才有效:
1) 将 android:supportsRtl="true"
属性放入您的 AndroidManifest 文件中以支持从右到左的布局方向。
2) 其次将此代码放入 activity 的 onCreate() 方法中:
if (getWindow().getDecorView().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR){
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
如果系统使用相应的语言,这将使您的所有内容从右到左放置。还要确保在设置填充时使用 start/end 而不是 left/right 以确保所有元素都正确对齐。
更多官方支持公告:http://android-developers.blogspot.be/2013/03/native-rtl-support-in-android-42.html
将 android:supportsRtl="true" 属性放入您的 AndroidManifest 文件中。 之后将以下行添加到您的工具栏标签:
android:layoutDirection="rtl"
对于那些希望右侧只有汉堡包图标并且工具栏中只有图标的用户,您可以使用
android:layoutDirection="rtl"
在工具栏标签上