我正在根据用户选择更改应用程序区域设置。独立于设备区域设置。
using
public void setDefaultLocale(Context context, String locale) {
Locale appLoc = new Locale(locale);
Locale.setDefault(appLoc);
Configuration appConfig = new Configuration();
appConfig.locale = appLoc;
context.getResources().updateConfiguration(appConfig,
context.getResources().getDisplayMetrics());
}
但我也想知道设备区域设置是什么。
当我尝试获取此信息时,我总是获取我为应用程序设置的区域设置。
例如:应用程序位于ENGLISH并且设备处于CHINESE。
我总是得到english.
为了获取区域设置使用,
选项1。
String locale = context.getResources().getConfiguration().locale.getCountry();
选项2。
String local_country = ((Activity) context).getBaseContext().getResources().getConfiguration().locale.getCountry();
任何帮助将不胜感激!
我问了类似的问题并找到了这个答案,抱歉如果晚了:
要查找系统区域设置,请使用:
defaultLocale = Resources.getSystem().getConfiguration().locale;
无论为应用程序/活动设置哪个默认区域设置,它都会获取系统区域设置。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)