android 使用 localse 来改变语言

标签 android android-resources

我想让我的应用程序多语言,我为它们使用了两个文件夹,第一个是默认的 valuesres里面文件夹,第二个是values-arres里面文件夹。当语言是英语时,一切都很完美。

现在,我想将其更改为 arabic .我使用了这段代码:

Locale locale = new Locale("ar");
    Locale.setDefault(locale);
    android.content.res.Configuration config = new android.content.res.Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());

当我使用该代码时,应用程序的指令如cutpaste已更改,但我不知道该告诉应用程序使用来自 values-ar 的变量文件夹,不是来自 values文件夹。

请不要担心编码问题

提前致谢

最佳答案

可以获取当前语言并设置if条件。

String currentLang = Locale.getDefault().getDisplayLanguage();

if(currentLang == "english"){
      //TODO
 }else if(currentLang == "yourLang"){
     //TODO
 }

希望您会发现这很有用。 干杯

关于android 使用 localse 来改变语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17650601/

相关文章:

android - 如何在 ROM 版本中安装默认的 AOSP 启动器快捷方式?

javascript - 在网页 View 中使用 Javascript

android - Android Studio 中的变量安全

android - 将 Android 应用中的语言更改为不受支持的语言

Android CircularReveal 库查看可见性错误

android - 在线性布局中居中图像

java - 找不到参数的compileOptions()方法

Android 添加 "values-en"文件夹导致 "Couldn' t 解析资源”警告

android - 造型 Sherlock 操作栏

Android Home As Up Indicator 文件名或位置