android - 如何强制 React Native 应用程序只是 RTL?

标签 android react-native android-studio android-layout

我有一个应用程序是用原生 react 编写的,应用程序中的所有内容都使用“阿拉伯语和布局”

所以我也想强制应用程序为 RTL 和布局,所以我使用来自 RN 的 I18nManager 来完成它,它在调试版本中工作正常“当我的移动语言 LTR 或 RTL 工作完美时”

/**
 * @format
 */

import {AppRegistry, I18nManager} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

I18nManager.forceRTL(true);

AppRegistry.registerComponent(appName, () => App);

但是当我的移动语言 RTL“阿拉伯语”布局和其他工作正常时,当我为 Play Store 发布 apk 版本时,但是当我的移动语言是 LTR“英语”时,布局发生变化,所有事情

所以我想强制我的应用程序成为 RTL,无论移动语言“阿拉伯语还是英语”

最佳答案

转到文件

MainApplication.java in this directory : android/app/src/main/java/com/YOUR_PROJECT_NAME



并添加此代码
I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
sharedI18nUtilInstance.forceRTL(this,true);
sharedI18nUtilInstance.allowRTL(this, true);

创建 那里的方法,
也不要忘记导入这个:
import com.facebook.react.modules.i18nmanager.I18nUtil;

关于android - 如何强制 React Native 应用程序只是 RTL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59071472/

相关文章:

java - 用于为我的应用程序选择启动语言的菜单(Android SDK)

reactjs - react 导航 v5 中的 tabBarIcon 问题

android - 如何解决 Android Studio 中的 IDE 错误?

android-studio - 运行flutter blue插件时出现错误: package androidx. core.app不存在

android - ActionBar 图标不与我的图标一起显示

android - 安卓录音机

java - 主要 Activity 的后退按钮 - 正常行为?

javascript - undefined 不是 React Native 的函数

javascript - ListItem onPress 无法正常工作

安卓工作室 : Symbol not found error