Android: Avoid passing null as the view root

时间:2021-11-21 23:35:29

在做一个应用时把Android SDK从4.4换成6.0,使用LayoutInflater的inflate方法时出现以下情

LayoutInflater.inflate(int resource, ViewGroup root)

参数root为null时,出现warning提示

Avoid passing null as the view root (needed to resolve layout parameters on the inflated layout's root element)

建议添加

@SuppressLint("InflateParams")

在网上查了,如果改用View的inflate方法root为null就不会出现warning提示

View.inflate(Context context, int resource, ViewGroup root)