RTL 无法正常工作

RTL is not working properly

我目前正在开发需要支持英语和阿拉伯语的 Android 应用程序,我正在使用此代码从一种语言切换到另一种语言。

String languageToLoad; // your language
    if (languageSwitch.isChecked()) {
        languageToLoad = "ar";//arabic
    } else {
        languageToLoad = "en";//english
    }

    Locale locale = new Locale(languageToLoad);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;

    // store it in the cache for any further use
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());
    SharedPreferencesUtil.putString(this, "language", languageToLoad);

工作正常,我制作了 2 个布局文件夹,一个普通文件夹和一个 layout-ar。它工作正常,但有时会出错,它没有显示阿拉伯语,而是显示英语布局,并且应用程序仅在英语模式下继续 运行。

最后你应该重新启动 activity。试试这个。

 public void updateActivity() {
        Intent intent = new Intent(getActivity(), MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }

事实证明,webview 是导致问题的原因,一旦生成 webview,它会删除所有覆盖的本地数据并从设备插入数据,为了更正问题,您需要遵循.

中找到的步骤