我知道創建一個新的語言代碼的後綴語言的值目錄。對於德語:values-de或french:values-fr,然後將我們的string.xml複製到該文件中並翻譯每個條目。而這項工作基於電話本地化設置自定義多語言支持
我想知道我們是否可以繞過手機設置,並讓用戶在應用程序內選擇他所需的語言?我的要求是,我想給我的應用程序內的語言選擇選項,並讓用戶選擇他想要的應用程序的語言..如何動態地在string.xml(用於不同的語言)之間切換? ?
在此先感謝
我知道創建一個新的語言代碼的後綴語言的值目錄。對於德語:values-de或french:values-fr,然後將我們的string.xml複製到該文件中並翻譯每個條目。而這項工作基於電話本地化設置自定義多語言支持
我想知道我們是否可以繞過手機設置,並讓用戶在應用程序內選擇他所需的語言?我的要求是,我想給我的應用程序內的語言選擇選項,並讓用戶選擇他想要的應用程序的語言..如何動態地在string.xml(用於不同的語言)之間切換? ?
在此先感謝
看看這篇文章...基本上是一樣的。
Changing Locale within the app itself
Locale appLoc = new Locale("en");
Locale.setDefault(appLoc);
Configuration appConfig = new Configuration();
appConfig.locale = appLoc;
getBaseContext().getResources().updateConfiguration(appConfig,
getBaseContext().getResources().getDisplayMetrics());
創建方法,將您的基本Locale.Lets說,當用戶選擇的語言環境
public static void setDefaultLocale(Context context,String locale) {
Locale locJa = new Locale(locale);
Locale.setDefault(locJa);
Configuration config = new Configuration();
config.locale = locJa;
context.getResources().updateConfiguration(config, context.getResources()
.getDisplayMetrics());
locJa = null;
config = null;
}
現在檢查。(這裏的語言選擇基本上我已經使用的菜單)。
Configuration config = new Configuration();
String newLocale = config.locale.getLanguage().substring(0, 2)
.toLowerCase();
if ("ja".equalsIgnoreCase(newLocale)) {
// Call above method with context & newLocale
}
// Sequentially you check for Locale & change that.
你爲什麼設置locJa和配置爲null setDefaultLocale結束的任何原因?他們即將超出範圍... – 2011-02-10 23:59:38
不,沒有理由背後設置它們爲空。這裏發佈的方法代碼直接來自我的應用程序,所以我正在製作它們,因爲我的應用程序中沒有使用它。 – 2011-02-11 03:18:45
+1好東西來解釋事情 – Naved 2011-09-22 10:26:11
如果你要根據各自的語言獲得的圖像,您應該創建像下面我this.First採取定製的本地化示例佈局中的文件夾。
Locale appLoc = new Locale("xx");
Locale.setDefault(appLoc);
Configuration appConfig = new Configuration();
appConfig.locale = appLoc;
getBaseContext().getResources().updateConfiguration(appConfig,
getBaseContext().getResources().getDisplayMetrics());
您的佈局文件夾應該是佈局-XX和你的繪製文件夾也應該繪製-xx.But一兩件事,當你改變的語言,你必須刷新我的應用程序使用的layout.I,取一個按鈕,並設置背景圖像。但有時圖像不會改變,所以我這樣做。
btn.setBackgroundDrawable(null);
btn.setBackgroundResource(R.drwable.yourimage);
It is very easy just follow this link
languageToLoad = "hi"; // your language
locale = new Locale(languageToLoad);
Locale.setDefault(locale);
config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
this.setContentView(R.layout.activity_main);
- 多見於:http://www.theappguruz.com/blog/multi-language-support-to-android-app#sthash.eGmzq57K.dpuf
您可以使用下面的庫,它提供的語言列表中,偏好設置屏幕,並覆蓋語言在你的應用程序:https://github.com/delight-im/Android-Languages – caw 2014-03-24 01:57:05