Android 如何从SettingsActivity更改应用程序的区域设置?

Android 如何从SettingsActivity更改应用程序的区域设置?,android,Android,我想从设置更改应用程序的语言 public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preference

我想从设置更改应用程序的语言

    public boolean onPreferenceChange(Preference preference, Object value) {
                String stringValue = value.toString();

                if (preference instanceof ListPreference) {
                    // For list preferences, look up the correct display value in
                    // the preference's 'entries' list.
                    ListPreference listPreference = (ListPreference) preference;
                    int index = listPreference.findIndexOfValue(stringValue);

                    // Set the summary to reflect the new value.
                    preference.setSummary(index >= 0 ? listPreference.getEntries()[index]: null);

                    .............
这里,在“设置”活动中,我们如何访问应用程序的配置和区域设置以更改其语言

仅供参考,我已将字符串转换为值。

请检查此代码

  public static final String ARABIC = "ar";
    public static final String ENGLISH = "en";
 public static void changeLoc(Activity context, int flagLang)
    {
        Resources res = context.getResources();
        // Change locale settings in the app.
        DisplayMetrics dm = res.getDisplayMetrics();
        android.content.res.Configuration conf = res.getConfiguration();

        if(flagLang == 0)
        {
            //english
            conf.locale = new Locale(ENGLISH);

        }
        else
        {
            //arabic
            conf.locale = new Locale(ARABIC);
        }
        res.updateConfiguration(conf, dm);
    }

应用程序重新启动时,此代码是否会持续?是,此代码将强制应用程序收听您的设置并忽略语言电话设置。您应该将当前语言保存在SharedReferences中,并在开始活动时从shared获取save language并调用此方法。这是的副本吗?