在将语言从英语切换到阿拉伯语时,布局从左到右变化。如何从左到右更改 textView。示例(英文)Ramesh 以 34 公里/小时的速度驾驶。(阿拉伯语) hpmk43 fo deeps a htiw gnivird hsemaR
编辑1:请找出下面的图片是否正确?
在将语言从英语切换到阿拉伯语时,布局从左到右变化。如何从左到右更改 textView。示例(英文)Ramesh 以 34 公里/小时的速度驾驶。(阿拉伯语) hpmk43 fo deeps a htiw gnivird hsemaR
编辑1:请找出下面的图片是否正确?
setLocale("en");
//设置英文
setLocale("ar");
//设置阿拉伯语
public void setLocale(String lang) {
Locale locale = new Locale(lang);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
}
将语言环境设置为英语和 LTR 将语言环境设置为阿拉伯语后将自动 RTL。//不要忘记重新启动您的应用程序。设置语言环境后
无需改变重力
要TextView
为 RTL 工作,您应该添加 RTL 的布局属性。
使用android:layout_marginStart
代替android:layout_marginLeft
和
android:layout_marginEnd
代替android:layout_marginRight
对于left-to-right
流量,start=left
,end=right
。
对于right-to-left
流量,start=right
,end=left
。
这种 RTL 支持是在 API 级别 17 中添加的,作为 Android 4.2 对 RTL 布局的支持的一部分。这将对您有所帮助 https://developer.android.com/about/versions/android-4.2.html#RTL
将您应用的所有left/right
布局属性更改为新的start/end
等效项。
简单的例子,使用 in android:gravity
。
不要忘记在您的应用中声明Manifest
您的应用支持 RTL 镜像:添加android:supportsRtl="true"
到Manifest
文件中的元素。