Android获取系统语言

获取系统语言(兼容7.0)- https://blog.csdn.net/ys743276112/article/details/71547134
在 Android 7.0 上:getResources().getConfiguration().locale 被标记为 deprecated 了,所以初步适配后是:
Locale locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    locale = getResources().getConfiguration().getLocales().get(0);
} else {
    locale = getResources().getConfiguration().locale;
}
//或者仅仅使用 locale = Locale.getDefault(); 不需要考虑接口 deprecated(弃用)问题
String lang = locale.getLanguage() + "-" + locale.getCountry();

猜你喜欢

转载自blog.csdn.net/ShareUs/article/details/86562404