翻译成阿拉伯语(本地化)问题

Translate into Arabic (Localization) issue

我正在尝试让我的应用程序支持阿拉伯语和英语
我做到了,但它在某些 android 版本中效果不佳,我不知道他们中的哪个...


this working well


but this not working well


我正在使用以下代码创建应用程序的均值 activity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String localLanguage = MySingleton.getmInstance(this).getAppLang();
    if (localLanguage.equals(getString(R.string.settings_language_arabic_value))) {
        Locale localeAr = new Locale("ar");
        setLocale(localeAr, getString(R.string.settings_language_arabic_value));
    } else if (localLanguage.equals(getString(R.string.settings_language_english_value))) {
        Locale localeEn = new Locale("en");
        setLocale(localeEn, getString(R.string.settings_language_english_value));
    }
    setContentView(R.layout.activity_branches);
    .......
    .......
 }

 private void setLocale(Locale locale, String lang) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        if (lang.equals(getString(R.string.settings_language_arabic_value)))
            config.setLayoutDirection(new Locale("ar"));
        else config.setLayoutDirection(new Locale("en"));
        getApplicationContext().getResources().updateConfiguration(config, null);
    } else {
        Configuration config = new Configuration();
        config.locale = locale;
        if (lang.equals(getString(R.string.settings_language_arabic_value)))
            config.setLayoutDirection(new Locale("ar"));
        else config.setLayoutDirection(new Locale("en"));
        Locale.setDefault(config.locale);
        Resources resources = getResources();
        resources.updateConfiguration(config, resources.getDisplayMetrics());
    }
}

如果有人能帮我一把,他会成就我的一天
提前致谢

我终于想出了一个解决办法..
谁要就分享

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String localLanguage = MySingleton.getmInstance(this).getAppLang();
    if (localLanguage.equals(getString(R.string.settings_language_arabic_value))) {
        setLocale("ar", this);
    } else if (localLanguage.equals(getString(R.string.settings_language_english_value))) {
        Locale localeEn = new Locale("en");
        setLocale("en", this);
    }
    setContentView(R.layout.activity_branches);
    .........
    .........
}

代码的变化在这里:

private void setLocale(String lang, Context context) {
    Configuration config = context.getResources().getConfiguration();
    Locale locale = new Locale(lang);
    Locale.setDefault(locale);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        config.setLocale(locale);
        getApplicationContext().getResources().updateConfiguration(config, null);
    } else {
        config.locale = locale;
        getApplicationContext().getResources().updateConfiguration(config, null);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        config.setLocale(locale);
        config.setLayoutDirection(locale);
        context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
        context.createConfigurationContext(config);
    } else {
        context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
    }
}


希望对大家有所帮助