2012-06-13 164 views
3

可能重複(而不是讓用戶去通過設置?):
Set Locale programatically是否可以手動設置語言,我的應用程序

我想創造一個英語/西班牙語選項的選擇,並想知道我是否可以利用Android的出色語言分支而不需要通過設置來改變整個設備的語言設置。

我明白如何自己拼湊它,如果這是不可能的,只是手動設置我所有的值,但希望我忽略了一些方法,讓Android使用它的語言系統爲我的應用程序,即使其餘系統的剩餘部分保持在預設的範圍內。

TIA

回答

3

是的,有可能通過你的Android應用程序設置語言,這樣的變化是從您的應用程序纔可見:

Locale locale = new Locale("us"); 
Locale.setDefault(locale); 
android.content.res.Configuration config = new android.content.res.Configuration(); 
config.locale = locale; 
context.getResources().updateConfiguration(config, this.getResources().getDisplayMetrics()); 

我認爲這會幫助你。

+0

可愛,這正是我想要的。 –

2
Resources res = getApplicationContext().getResources(); 

Locale locale = new Locale("us"); 
Locale.setDefault(locale); 

Configuration config = new Configuration(); 
config.locale = locale; 

res.updateConfiguration(config, res.getDisplayMetrics()); 
相關問題