Я локализую приложение android и добавляю кнопку изменения языка. Но как только я нажимаю кнопку языка, он меняет этот язык для всех действий и фрагментов, когда я помещаю в строковую папку, но язык элементов меню на ползунке не меняет язык. Это мой код изменения языка. `publi c class Settings extends Fragment {Locale myLocale;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_settings, container, false);
///String [] values =
/// {"Please Select Language","Myanmar","English",};
Spinner spinner = (Spinner) v.findViewById(R.id.spinner1);
/// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, values);
/// adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
/// spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener () {
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
if (pos == 1) {
Toast.makeText(parent.getContext(),
"You have selected Myanmar", Toast.LENGTH_SHORT)
.show();
saveLocale("my");
} else if (pos == 2) {
Toast.makeText(parent.getContext(),
"You have selected English", Toast.LENGTH_SHORT)
.show();
saveLocale("en");
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
return v;
}
public void setLocale(String lang) {
// Create a new Locale object
myLocale = new Locale(lang);
Locale.setDefault(myLocale);
// Create a new configuration object
Configuration config = new Configuration();
// Set the locale of the new configuration
config.locale = myLocale;
// Update the configuration of the Accplication context
getResources().updateConfiguration(
config,
getResources().getDisplayMetrics()
);
}
public void saveLocale(String language) {
SharedPreferences sharedPreferences = this.getActivity().getSharedPreferences("pref", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("USER_LANGUAGE", language);
editor.commit();
LoadLanguage ();
FragmentTransaction t = getActivity().getSupportFragmentManager().beginTransaction();
t.setReorderingAllowed (false);
t.detach(this).attach(this).commitAllowingStateLoss();
}
public void LoadLanguage(){
SharedPreferences sharedPreferences = this.getActivity().getSharedPreferences("pref", Context.MODE_PRIVATE);
String language = sharedPreferences.getString("USER_LANGUAGE","");
Locale locale = new Locale(language);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getResources().updateConfiguration(config, getResources().getDisplayMetrics());
}
}`