简体   繁体   中英

How make localization for toasts?

I'm wrote localization for ui texts using

String languageToLoad  = "en_EN";
 Locale locale = new Locale(languageToLoad); 
 Locale.setDefault(locale);
 Configuration config = new Configuration();
 config.locale = locale;
 context.getResources().updateConfiguration(config,context.getResources().getDisplayMetrics());

This good working for UI views, but my toasts don't have this. How fix it? Strings was created in strings.xml with Locale qualifier.

This is quite easy:

String string = getString(R.string.your_string_name);

If the string is saved in the right language folder it will be localised automatically.

Read more here: https://developer.android.com/guide/topics/resources/string-resource#:~:text=android%3Atext%3D%22%40string%2Fhello%22%20%2F%3E&text=String%20string%20%3D%20getString%20(R.,int)%20to%20retrieve%20a%20string .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM