今天使用LayoutInflate.inflate()方法加载一个布局,当参数root 为null 时,出现下列提示
Avoid passing null as the view root (needed to resolve layout parameters on the inflated layout's root element)
解决方案:
1. 添加:
@SuppressLint("InflateParams")
2. 修改成
view = View.inflate(context,R.layout.custom_layout,null);
改用View的inflate方法root为null就不会出现warning提示。