对齐工具栏图标自右向左? [英] Align Toolbar icons from right to left?
问题描述
在我的应用程序,我已经实现了一些语言包括阿拉伯语语言,从右开始向左。我想对齐工具栏的所有图标是 RIGHT_TO_LEFT
。
In my application, I have implemented some languages including Arabic language which starts from Right to Left. I want to align all icons in the Toolbar be RIGHT_TO_LEFT
.
我试过 layout_gravity =正确的
和比重=正确的
但是,没有发梗。
I tried layout_gravity="right"
and gravity="right"
But nothing happed.
我的工具栏code:
<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的工作:
Official right-to-left support was introduced with Android 4.2 (API level 17), so this will only work if your minimum SDK level is 17:
1)把安卓supportsRtl =真正的
属性在AndroidManifest文件,以支持从右到左的布局方向
1) Put the android:supportsRtl="true"
attribute in your AndroidManifest file to support right-to-Left layout directions.
2)其次把这个code。在您的活动的onCreate()methdod:
2) Secondly put this code in your activity's onCreate() methdod:
if (getWindow().getDecorView().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR){
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
这会让你的一切都放在从右到左如果系统使用一个根据语言。另外,还要确保设置时的填充,以确保所有的元素都正确对齐您使用的开始/结束,而不是左/右。
This will make your everything is placed from right to left if the system uses an according language. Also make sure you use start/end instead of left/right when setting up padding to make sure that all elements are aligned correctly.
有关的官方支持公告的详细信息:<一href="http://android-developers.blogspot.be/2013/03/native-rtl-support-in-android-42.html">http://android-developers.blogspot.be/2013/03/native-rtl-support-in-android-42.html
For more information about the official support announcement: http://android-developers.blogspot.be/2013/03/native-rtl-support-in-android-42.html
这篇关于对齐工具栏图标自右向左?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!