Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Can';在安卓设备中不改变语言_Android - Fatal编程技术网

Android Can';在安卓设备中不改变语言

Android Can';在安卓设备中不改变语言,android,Android,我正在尝试在我的应用程序中更改设备的语言。我有以下代码: Locale locale = new Locale("en_US"); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getApplicationContext().getResources().updateConfiguration(config, null); Log.i("some","

我正在尝试在我的应用程序中更改设备的语言。我有以下代码:

Locale locale = new Locale("en_US"); 
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getApplicationContext().getResources().updateConfiguration(config, null);
Log.i("some","Well, I tried!");
但这段代码不会改变我的设备的状态,在LogCat中我可以看到“嗯,我试过了”的消息。这种奇怪行为的可能原因是什么?

编辑这一行

getApplicationContext().getResources().updateConfiguration(config, null);
像这样:

context.getApplicationContext().getResources().updateConfiguration(config, null);

手动更改应用程序区域设置

您需要使用下面的代码设置区域设置

Locale locale = new Locale("AR"); // AR here is for arabic
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, 
getBaseContext().getResources().getDisplayMetrics());
在调用“setContentView”方法之前,请确保在activity“onCreate”方法中设置了它


另外,请查看为所需语言指定的资源文件。

我是否需要为我拥有的每个活动执行此操作?这只会更改活动的区域设置。它不会改变设备的区域设置。谢谢,我尝试了这个,但是我的设备语言仍然没有改变。相反,我的应用程序的区域设置发生了变化。对不起,我不明白这个问题。我需要更改应用程序中设备的语言-检查一下这个也谢谢你,我一定会这么做的。