//获取 Locale 的方式有二 //方式一 Locale locale = getResources().getConfiguration().locale; //方式二 Locale locale = Locale.getDefault(); //获取当前系统语言 locale.getLanguage();
//获取 Locale 的方式有二 //方式一 Locale locale = getResources().getConfiguration().locale; //方式二 Locale locale = Locale.getDefault(); // 获取当前系统语言 String lang = locale.getLanguage() + "-" + locale.getCountry();
//获取 Locale 对象的正确姿势:
Locale locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
locale = getResources().getConfiguration().getLocales().get(0);
} else {
locale = getResources().getConfiguration().locale;
}
//获取语言的正确姿势:
String lang = locale.getLanguage() + "-" + locale.getCountry();
Locale locale = Locale.getDefault();
MLog.e(locale.getLanguage() + "-" + locale.getCountry());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
LocaleList localeList = getResources().getConfiguration().getLocales();
for (int i = 0; i < localeList.size(); i++) {
MLog.e(i + " >1> " + localeList.get(i).getLanguage() + "-" + localeList.get(i).getCountry());
}
LocaleList localeList2 = LocaleList.getAdjustedDefault();
for (int i = 0; i < localeList2.size(); i++) {
MLog.e(i + " >2> " + localeList2.get(i).getLanguage() + "-" + localeList2.get(i).getCountry());
}
LocaleList localeList3 = LocaleList.getDefault();
for (int i = 0; i < localeList3.size(); i++) {
MLog.e(i + " >3> " + localeList3.get(i).getLanguage() + "-" + localeList3.get(i).getCountry());
}
LocaleList localeList4 = LocaleList.getEmptyLocaleList();
for (int i = 0; i < localeList4.size(); i++) {
MLog.e(i + " >4> " + localeList4.get(i).getLanguage() + "-" + localeList4.get(i).getCountry());
}
}
zh-CN 0 >1> zh-CN 1 >1> hi-IN 2 >1> en-US 3 >1> zh-HK 0 >2> zh-CN 1 >2> hi-IN 2 >2> en-US 3 >2> zh-HK 0 >3> hi-IN 1 >3> zh-CN 2 >3> en-US 3 >3> zh-HK
en-US 0 >1> en-US 1 >1> hi-IN 2 >1> zh-CN 3 >1> zh-HK 0 >2> en-US 1 >2> hi-IN 2 >2> zh-CN 3 >2> zh-HK 0 >3> hi-IN 1 >3> en-US 2 >3> zh-CN 3 >3> zh-HK
Locale locale = Locale.getDefault(); //Locale.getDefault() 和 LocaleList.getAdjustedDefault().get(0) 同等效果,还不需要考虑版本问题,推荐直接使用 String language = locale.getLanguage() + "-" + locale.getCountry();
Locale locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
locale = LocaleList.getDefault().get(0);
} else {
locale = Locale.getDefault();
}
String language = locale.getLanguage() + "-" + locale.getCountry();
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有