我希望让我的React Native应用程序支持RTL。
如https://facebook.github.io/react-native/blog/2016/08/19/right-to-left-support-for-react-native-apps.html所述,以下方法可以实现:
I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
sharedI18nUtilInstance.setAllowRTL(context, true);
然而,为了获得下面所使用的上下文:
sharedI18nUtilInstance.allowRTL(getApplicationContext(),true);
但是我遇到了 NullPointerException
的问题。
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:106)
at com.nativestarterkit.MainActivity.getMainComponentName(MainActivity.java:18)
at com.facebook.react.ReactActivity.createReactActivityDelegate(ReactActivity.java:48)
at com.facebook.react.ReactActivity.<init>(ReactActivity.java:32)
at com.nativestarterkit.MainActivity.<init>(MainActivity.java:8)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2538)
... 9 more
onCreate(Bundle savedInstanceState)
然后是super.onCreate(savedInstanceState);
。 - Alireza Fattahi