在Android上反应原生RTL

Ted*_*Ted 6 java android react-native

试图在这里完成这几个步骤,以便我可以支持RTL: 使应用程序RTL准备就绪
我正在尝试MainActivity.java根据说明添加这些行:

I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
sharedI18nUtilInstance.setAllowRTL(context, true);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

(我不是原生Android开发人员,但尝试使用本机反应并偶尔访问Android源来修改更深层次的更改 - 这个不会编译.)

First,他们认为context应该在哪里定义?我无法想象这是一种全球性的......?

Second,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);
    }
}
Run Code Online (Sandbox Code Playgroud)

Max*_*man 9

在MainApplication.java中添加此导入:

import android.os.Bundle; // needed for onCreate method
import com.facebook.react.modules.i18nmanager.I18nUtil;
Run Code Online (Sandbox Code Playgroud)

并添加

@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
    sharedI18nUtilInstance.allowRTL(getApplicationContext(), true);
}
Run Code Online (Sandbox Code Playgroud)