繁体   English   中英

如何为 toast 进行本地化?

[英]How make localization for toasts?

我正在使用为 ui 文本编写本地化

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());

这对 UI 视图很有用,但我的敬酒没有这个。 怎么修? 字符串是在 strings.xml 中使用区域设置限定符创建的。

这很容易:

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

如果字符串保存在正确的语言文件夹中,它将自动本地化。

在这里阅读更多: 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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