Ray*_*Ray 9 android react-native
标题说明了一切.我找到了几种使用Facebook的I18nManager将应用程序的默认布局设置为RTL的方法,但它仅在第二次应用程序启动时才这样做.
代码示例: I18nManager.forceRTL(true)
我不想让用户能够更改语言,因为应用程序本身是阿拉伯语.我到处搜索但是所有人都在讨论如何支持RTL而不是实际使用它作为默认布局.
有没有办法用I18nManager实现这一点,还是我必须对我的本机代码进行一些更改?
小智 8
首先在清单中添加rtl支持,如下所示.
<application
android:name=".application.SampleApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
</application>
Run Code Online (Sandbox Code Playgroud)
然后在您的启动器活动上,在oncreate上添加以下代码.
Locale locale = new Locale("ar");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getApplicationContext().getResources().updateConfiguration(config, getApplicationContext().getResources().getDisplayMetrics());
Run Code Online (Sandbox Code Playgroud)
将以下代码行添加到所有活动的onCreate方法的最顶部(在super和setContentView之前):
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
Run Code Online (Sandbox Code Playgroud)
并确保清单中的supportRtl等于True。
| 归档时间: |
|
| 查看次数: |
3703 次 |
| 最近记录: |