例如:我有一个多语言应用程序,我想从随机语言中得到一些字符串,用户必须猜测它是什么语言。 如何从其他语言获取单个字符串?如何从特定的“值”文件夹中获取字符串?
0
A
回答
1
应用程序使用的特定于语言的字符串取决于在android系统(Link)中设置的系统本地。所以Android会自动拍摄正确的值。您无法硬编码要使用的特定(或随机)值。
一种方式做事情是要改变编程机器人的本地设置:
Locale locale = new Locale("fr");
Configuration config = new Configuration();
config.locale = locale;
getResources().updateConfiguration(config, null);
getResources().getString(R.string.local_string);
在这种情况下做的唯一事情就是重新洗牌的本地标识符。当然,在更改本地权限之前,您应该确保本地权限的实例,以便您可以将其重置为原始状态。祝你好运;)
编辑:
这里是一些肮脏的代码,我写了验证:
Locale orgLocal = getResources().getConfiguration().locale;
String[] availLocales = { "fr", "de", "en" };
Locale tempLocale = new Locale(availLocales[new Random().nextInt(availLocales.length)]);
Configuration config = new Configuration();
config.locale = tempLocale;
getResources().updateConfiguration(config, null);
String randLangString = getResources().getString(R.string.local_string);
config.locale = orgLocal;
getResources().updateConfiguration(config, null);
Toast.makeText(this, randLangString, Toast.LENGTH_LONG).show();
0
首先使用此代码来改变语言设置
Locale locale = new Locale("kn");
Configuration config = new Configuration();
config.locale = locale;
getResources().updateConfiguration(config, null);
getResources().getString(R.string.local_string);
然后用于支持所有类型的语言使用 种Unicode字体like--“ARIALUNI.TTF”宋体的Unicode字体(复制到资源文件夹)
Typeface font= Typeface.createFromAsset(getAssets(), "ARIALUNI.TTF"); TextView tv1.setTypeface(font);
tv1.setText(R.string.txt);
* 从拿R.string.text值值烯为英语和价值观,KN文件夹kannada语言*
0
它非常令人惊讶,相信我们只能通过改变配置来启用我们想要的语言。根据需要
Locale locale;
locale = new Locale("fr","FR");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
this.getActivity().getResources().updateConfiguration(config, this.getActivity().getResources().getDisplayMetrics());
相关问题
- 1. 从字符串值文件夹中获取字符串数组?
- 2. 如何从_applicationObject获取文件中的特定字符串
- 3. 获取包含特定字符串的特定文件夹中的文件
- 4. 从字符串获取特定值
- 5. 如何从Lua中的字符串中获取特定文本?
- 6. 从特定字符的数组中的字符串获取值?
- 7. 如何从字符串(url)获取特定的字符串?
- 8. 如何从文本文件中读取特定的字符串
- 9. 从文本文件中获取特定的字符串
- 10. 如何从字符串的Arraylist中获取特定字符?
- 11. 如何从字符串中获取特定值?
- 12. 如何从Installshield中的文本文件中获取特定的字符串
- 13. 从值文件夹中获取字符串到类android
- 14. 从字符串获取特定字符
- 15. 如何从文件中获取特定行中的特定值?
- 16. 如何从文件中提取特定的字符串(Linux版)
- 17. 从Android的“值”文件夹获取字符串资源
- 18. 从字符串中提取特定值
- 19. 如何在文件中获取特定字符串
- 20. 如何从oracle中的字符串获取特定数字
- 21. VB.NET从指定文件夹中的多个文本文件中获取特定的字符串
- 22. 如何从字符串中获取值?
- 23. 从字符串文件中获取特定元素
- 24. 如何从PHP中的字符串中获取特定单词?
- 25. 如何从SQL中的字符串中获取特定部分
- 26. 从NSString获取特定的字符串
- 27. 如何从C#中的字符串中提取特定值
- 28. Swift3我如何获取字符串中特定键的值?
- 29. 如何从我的表中获取特定的字符串?
- 30. 如何使用键值对从文件中获取字符串?
谢谢。我会尝试 –