希望这不是我已经修复过的关于地区弃用context.getResources().getConfiguration().locale调用的许多其他问题的副本。
我如何摆脱以下代码的Lint警告:
public static String toDateString(Context context, Date date)
{
DateFormat format = Build.VERSION.SDK_INT >= 24 ?
DateFormat.getDateInstance(DateFormat.MEDIUM, context.getResources().getConfiguration().getLocales().get(0)) :
DateFormat.getDateInstance(DateFormat.MEDIUM, context.getResources().getConfiguration().locale);
return format.format(date);
}发布于 2018-08-19 20:29:35
您不应该直接使用属性。
请参阅getLocales
发布于 2018-08-19 20:29:41
首先,检查您当前的版本,并使用已弃用的版本。尝尝这个,
Locale locale;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
locale = this.getResources().getConfiguration().getLocales().get(0);
} else{
locale = this.getResources().getConfiguration().locale;
}你可以直接使用Locale.getDefault(),
https://stackoverflow.com/questions/51917535
复制相似问题