在安卓5.0更改应用程序的语言不工作 [英] Change app language in android 5.0 doesn't work

查看:221
本文介绍了在安卓5.0更改应用程序的语言不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面这个code来改变我的按钮,点击应用程序语言(法语切换到英语为例),它的正常工作在Android 4.0 +,但在5.0事实并非如此。

 区域设置localeEn =新的语言环境(EN_US);
Locale.setDefault(localeEn);
配置configEn =新配置();
configEn.locale = localeEn;
getApplicationContext()getResources()updateConfiguration(configEn,空)。
this.recreate();
 

任何线索为什么吗?

编辑: 这是我的清单(与Android:configChanges)

 <活动
            机器人:名称=。activities.LoginActivity
            机器人:configChanges =方向|语言环境
            机器人:标签=@字符串/ APP_NAME
            机器人:screenOrientation =画像/>
 

解决方案

尝试从这个改变:

 区域设置localeEn =新的语言环境(EN_US);
Locale.setDefault(localeEn);
 

 字符串LANGUAGE =EN;
字符串国家=美国;
区域设置区域设置=新的语言环境(语言,国家);
 

I'm using this code below to change my app language on button click (changing from french to english for example), it's works fine on android 4.0 + but on 5.0 it doesn't.

Locale localeEn = new Locale("en_US");
Locale.setDefault(localeEn);
Configuration configEn = new Configuration();
configEn.locale = localeEn;
getApplicationContext().getResources().updateConfiguration(configEn, null);
this.recreate();

Any clues why please?

edit : this is my manifest ( with android:configChanges )

<activity
            android:name=".activities.LoginActivity"
            android:configChanges="orientation|locale"
            android:label="@string/app_name"
            android:screenOrientation="portrait"/>

解决方案

Try to change from this:

Locale localeEn = new Locale("en_US");
Locale.setDefault(localeEn);

to this

String language = "en";
String country = "US";
Locale locale = new Locale(language , country);

这篇关于在安卓5.0更改应用程序的语言不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆