Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android AlertDialog setContentView接管屏幕_Android_View_Android Alertdialog - Fatal编程技术网

Android AlertDialog setContentView接管屏幕

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

也许我在这里遗漏了一些明显的东西,但我很难为AlertDialog的主体设置自定义视图。下面是我设置自定义视图的步骤:

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。它实际上是在一次创建对话框中,但我会试一试。谢谢