问题描述
我需要在Android Studio上获得设备Locale
,但显然以下代码仅适用于api级24+;我如何在较低级别的api中获得与这行代码相同的结果?
getResources().getConfiguration().getLocales().get(0);
解决方法
根据Google文档,该命令public Locale locale
已在API 24中弃用,并且您可以在24级以上的API级别中使用getLocales()
和setLocales(android.os.LocaleList)
。因此,您应该{{1 }},而不是较低的API。
configuration.locale
还要检查一下,说明一切:
,对于下层Lavel API,可以使用
Locale current = getResources().getConfiguration().locale;