尝试在此处执行以下几个步骤,以便我可以支持 RTL:
Making an App RTL-ready
我正在尝试根据说明将这些行添加到 MainActivity.java
:
I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
sharedI18nUtilInstance.setAllowRTL(context, true);
(我不是原生 Android 开发人员,但尝试使用 react native 并偶尔访问 Android 源代码以修改更深层次的更改 - 这个不会编译。)
首先
,他们认为应该在哪里定义context
?我无法想象它是全局性的......?
其次
,setAllowRTL 显示为红色...这似乎是一个编译错误。
知道他们的意思吗?我是否在正确的地方定义了它?
我的代码是这样的:
import com.facebook.react.ReactActivity;
import com.facebook.react.modules.i18nmanager.I18nUtil;
import android.content.Intent;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "myApp";
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
sharedI18nUtilInstance.setAllowRTL(context, true);
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
}
最佳答案
在 MainApplication.java 中添加此导入:
import android.os.Bundle; // needed for onCreate method
import com.facebook.react.modules.i18nmanager.I18nUtil;
并添加
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
sharedI18nUtilInstance.allowRTL(getApplicationContext(), true);
}
关于java - 在 Android 上 react native RTL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41655898/