GoogleMaps Android studio change language refresh

霸气de小男生 提交于 2020-01-05 07:35:29

问题


I am using a google map in an activity with multiple fragments, when changing the language from English to Arabic and vice versa from the settings page, i reload the whole activity to apply changes, every thing displays normally ei all text changes to the new language except the titles inside the map (country names, city, streets...)

this is the code i use to change the laguage:

 public static void setLanguage(Activity activity){
        String languageToLoad = "en";
        boolean isEnglish=Preference.getBooleanPrefs(Preference.LANGUAGE, activity, true);
        if(isEnglish)
            languageToLoad = "en";
        else
            languageToLoad = "ar";

        Locale locale = new Locale(languageToLoad);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        activity.getBaseContext().getResources().updateConfiguration(config,activity.getResources().getDisplayMetrics());

    }

this is the code i use to reload the activity:

public void refreshChangelanguage() {

        Intent intent = new Intent(this, HomeActivity.class);
        startActivity(intent);
        finish();
        loadFragment(FRAGMENT_SETTING, null);

    }

the map keeps displaying in the old language until i kill the whole app from the stack list manually then reopen it, how can i force the map to reload the labels in the new language?

thank you in advance


回答1:


I'd say you have to do the setLanguage(Activity activity) after the super.onCreate and before the setContentView on the Activity.



来源:https://stackoverflow.com/questions/42559878/googlemaps-android-studio-change-language-refresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!