Android AlertDialog setContentView接管屏幕
也许我在这里遗漏了一些明显的东西,但我很难为AlertDialog的主体设置自定义视图。下面是我设置自定义视图的步骤:Android AlertDialog setContentView接管屏幕,android,view,android-alertdialog,Android,View,Android Alertdialog,也许我在这里遗漏了一些明显的东西,但我很难为AlertDialog的主体设置自定义视图。下面是我设置自定义视图的步骤: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(View.inflate(getContext(), R.layout.dialog_body, null)); } 视图不是设置AlertDi
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(View.inflate(getContext(), R.layout.dialog_body, null));
}
视图不是设置AlertDialog主体的内容,而是放置在整个屏幕上。如何获取视图以替换AlertDialog消息正文?您通过调用
setContentView
来设置活动的视图,这就是它占据整个屏幕的原因。您还可以在我假设的活动的onCreate
方法中执行此操作,您需要在onCreateDialog
方法中执行此操作
这里有一个链接和一个例子
public Dialog onCreateDialog(int id) {
Dialog dialog = null;
AlertDialog.Builder builder = new AlertDialog.Builder(app);
AlertDialog alert = null;
builder.setTitle("A title")
.setCancelable(true)
.setView(myView);
alert = builder.create();
return alert;
}
您的活动是谁的onCreate函数?扩展AlertDialog的类。但是我用AlertDialog.Builder得到了它。我希望能有一个解决方案,用于一次创建AlertDialog。它实际上是在一次创建对话框中,但我会试一试。谢谢