Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.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为整个应用程序指定了区域设置_Android - Fatal编程技术网

android为整个应用程序指定了区域设置

android为整个应用程序指定了区域设置,android,Android,我的尝试如下 final Locale locale = new Locale("en", "US"); Locale.setDefault(locale); final Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config,

我的尝试如下

final Locale locale = new Locale("en", "US");
        Locale.setDefault(locale);
        final Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config,
                getBaseContext().getResources().getDisplayMetrics());

我想为整个应用程序设置一个特定的区域设置,我正在应用程序类级别上进行设置,但是上面给出的行似乎不起作用,因为当我从设置中更改区域设置语言规范时,日期选择器不具有应用程序类指定区域设置的效果,并且从设置语言规范中获取区域设置。

我不确定在应用程序级别设置区域设置是否有效,因为我自己没试过

一个解决方法(我知道是可行的)是创建一个超级活动,例如
MyActivity扩展活动
。输入密码

final Locale locale = new Locale("en", "US");
Locale.setDefault(locale);
final Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());

在MyActivity的
onCreate()
方法中,让您的所有活动扩展MyActivity而不是Activity。

我不确定是否完全理解您的问题。问题是应用程序没有以正确的语言显示string.xml中的文本吗?不,我想将en us设置为整个应用程序的语言,即使更改设置中的语言也不会影响我的应用程序。请看!我在我的一个应用程序中做了一些非常类似的事情,使用与上面相同的代码。我能发现的唯一区别是,我是在活动级别而不是在应用程序级别进行操作的。我建议您将代码移动到活动的onCreate/onResume方法之一,看看这是否有帮助。是的,但我想为我的整个应用程序而不是特定的活动执行此操作,是否可能??因为为每个活动执行可能会增加不必要的代码重复。有什么方法可以在应用程序课上做同样的事情吗?我不知道。我的应用程序中还有一些其他要求,这使得我无法将其设置为应用程序级别。一个想法是使用自定义超级活动,例如MyActivity扩展活动。将代码放在MyActivity的onCreate方法中,让所有活动扩展MyActivity而不是Activity。