android – 避免传递null作为视图根(在AlertDialog中膨胀自定义布局时)
作者:互联网
试图为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 content = inflater.inflate(R.layout.dialog_customd, parent, false);
标签:android-alertdialog,android,layout-inflater,android-layout 来源: https://codeday.me/bug/20190823/1699543.html