2012-09-19 94 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()); 
相關問題