如何创建本地方言不同的应用程序?

时间:2018-04-24 20:52:55

标签: java android multilingual

我之前测试过这些代码,但错误提供了一个过时的语言环境

public static void setLanguage(Context context, String languageCode){
Locale locale = new Locale(languageCode);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;  // Deprecated !!
context.getApplicationContext().getResources().updateConfiguration(config,
        context.getResources().getDisplayMetrics());

}

1 个答案:

答案 0 :(得分:0)

您的应用程序中应该有一个位于res/values/strings.xml

中的名为String.xml的文件

您应将所有文字放在该文件中

例如

<resources>     
  <string name="title">Test</string>
  <string name="message">Test</string>
</resources>

这是将字符串值设置为Textview

的方法

例如

      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"     
        android:text="@string/title" />

因此,当您决定要添加更多语言时,您需要在资源文件夹中创建其他string.xml文件,并在其中添加已翻译的字符串。文件夹“values-hi”下面的例子是指印地语,

例如。

MyProject/
res/
   values/
       strings.xml
   values-hi/
       strings.xml

然后android会根据设备配置自动本地化语言。

有关更多详细信息,请参阅此链接 https://developer.android.com/training/basics/supporting-devices/languages.html

相关问题