如何在Android设备中选择当前语言?
当前回答
我的解是这样的
@SuppressWarnings("deprecation")
public String getCurrentLocale2() {
return Resources.getSystem().getConfiguration().locale.getLanguage();
}
@TargetApi(Build.VERSION_CODES.N)
public Locale getCurrentLocale() {
getResources();
return Resources.getSystem().getConfiguration().getLocales().get(0);
}
然后
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Log.e("Locale", getCurrentLocale().getLanguage());
} else {
Log.e("Locale", getCurrentLocale2().toString());
}
显示——>和
其他回答
基本的Kotlin答案:
Locale.getDefault().language
如果你想要获得你的设备所选择的语言,这可能会帮助你:
Locale.getDefault().getDisplayLanguage();
你可以使用Locale.getDefault().getLanguage();要获得常用的语言代码(例如:“德”、“en”)
您可以从当前区域“提取”语言。你可以通过标准的Java API或者使用Android Context来提取语言环境。例如,下面这两行是等价的:
String locale = context.getResources().getConfiguration().locale.getDisplayName();
String locale = java.util.Locale.getDefault().getDisplayName();
如果你使用喷气背包撰写
在可组合功能方面
Context.applicationContext.resources.configuration.locales.get(0).language
if(Locale.getDefault().getDisplayName().equals("हिन्दी (भारत)")){
// your code here
}
推荐文章
- 我如何在一个片段中访问getSupportFragmentManager() ?
- 调试在哪里。Android Studio中的密钥存储库
- 从资产中读取文件
- 在不活动的地方调用getLayoutInflater()
- 设置Android布局元素的背景颜色
- 错误:'keytool'不能被识别为内部或外部命令、可操作程序或批处理文件
- 在应用程序本身中更改Locale
- apk (.apk)和应用程序包(.aab)的区别
- 如何设置超时在改造库?
- Android - SPAN_EXCLUSIVE_EXCLUSIVE跨度不能为零长度
- TextView的字体大小在Android应用程序改变字体大小从本机设置
- 如何模拟Android杀死我的进程
- 禁用EditText闪烁光标
- Android Eclipse -无法找到*.apk
- 设置TextView文本从html格式的字符串资源在XML