2012-09-19 93 views

回答

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

谢谢。我会尝试 –

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()); 
相关问题