欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android編程實現(xiàn)動態(tài)支持多語言的方法

 更新時間:2017年06月14日 09:37:40   作者:_iorilan  
這篇文章主要介紹了Android編程實現(xiàn)動態(tài)支持多語言的方法,涉及Android資源、控件及屬性相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了Android編程實現(xiàn)動態(tài)支持多語言的方法。分享給大家供大家參考,具體如下:

資源文件values/strings.xml中添加

<string name="current_language">English</string>
<string name="test">test</string>

創(chuàng)建values-en文件夾,添加資源文件 strings.xml:

<resources>
<string name="current_language">English</string>
<string name="test">test</string>
</resources>

創(chuàng)建values-zh文件夾,添加資源文件 strings.xml

<resources>
<string name="current_language">Chinese</string>
<string name="test">測試</string>
</resources>

MainActivity layout中添加測試控件

<TextView
...
text = "@string/userid"
...
/>

Main Activity 中添加代碼:

public class MainActivity ...
{
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    updateResources(this,"zh");
    ...
  }
}
private static boolean updateResources(Context context, String language) {
    Locale locale = new Locale(language);
    Locale.setDefault(locale);
    Resources resources = context.getResources();
    Configuration configuration = resources.getConfiguration();
    configuration.locale = locale;
    resources.updateConfiguration(configuration, resources.getDisplayMetrics());
    return true;
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

最新評論