因此,在我的應用程序中,用戶看到的第一個活動是選擇語言。爲什麼用戶在我的應用程序中更改語言時android:label的文本不會更改?
假設用戶選擇法語,然後轉到ActivityB,然後轉到ActivityC。
現在決定改變語言。
因此返回到ActivityB,然後返回到第一個Activity並選擇西班牙語。
現在當用戶轉到ActivityB時,片段/活動中的所有其他文本都會更改爲西班牙語,但android:label仍然保留爲法語。如何解決這個問題?
這是我ActivityA外觀
public View onCreateView(LayoutInflater inflater, ViewGroup container,
final Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_choose_language, container, false);
radioGroup = (RadioGroup) rootView.findViewById(R.id.lang_choice_radio);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch(checkedId){
case R.id.english_lang:
// do operations specific to this selection
setLocale("en_US");
Intent intentEng = new Intent(getActivity(), Choose_Country.class);
startActivity(intentEng);
break;
case R.id.indonesian_lang:
// do operations specific to this selection
setLocale("in");
Intent intent = new Intent(getActivity(), Choose_Country.class);
startActivity(intent);
break;
}
}
});
return rootView;
}
public void setLocale(String lang) {
myLocale = new Locale(lang);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Locale.setDefault(myLocale);
onConfigurationChanged(conf);
Intent refreshIntent = new Intent(getActivity(), ChooseLanguage.class); // refresh the activity
refreshIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
refreshIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(refreshIntent);
getActivity().finish();
}
將
這就是它的原理。 – user3705478
您正在完成此行上的活動getActivity()。finish();那麼用戶如何導航回[從活動B]到這個活動[A]? –