尝试为 AlertDialog 扩展自定义布局,但不断收到此警告。我已经看到了几种不同的解决方案,但不知道哪个适合我的场景。摆脱此空警告的实际正确方法是什么?
Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element)
@Override
public void onClick(View v) {
AlertDialog alertDialog = new
AlertDialog.Builder(getActivity()).create();
LayoutInflater inflater = getActivity().getLayoutInflater();
View content = inflater.inflate(R.layout.dialog_customd, null);
alertDialog.setView(content);
alertDialog.show();
}
最佳答案
您可以尝试使用:
View.inflate(context, R.layout.dialog_customd, null);
关于android - 避免将 null 作为 View 根传递(在 AlertDialog 中扩展自定义布局时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45419680/