如何将图片添加到android.support.v7.app.AlertDialog

如何将图片添加到android.support.v7.app.AlertDialog,android,dialog,alert,Android,Dialog,Alert,文档说明如下: android.support.v7.app.AlertDialog alert = builder.create(); ImageView myView = new ImageView(mContext); myView.setImageResource(R.drawable.image); FrameLayout f1 = (FrameLayout) findViewById(android.R.id.custom); f1.addView(myView, new Lay

文档说明如下:

android.support.v7.app.AlertDialog alert = builder.create();

ImageView myView = new ImageView(mContext);
myView.setImageResource(R.drawable.image);

FrameLayout f1 = (FrameLayout) findViewById(android.R.id.custom);
f1.addView(myView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

alert.show();
如果要显示更复杂的视图,请查阅FrameLayout 调用“自定义”并将视图添加到其中:

FrameLayout fl = (FrameLayout) findViewById(android.R.id.custom);
 fl.addView(myView, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
我的代码如下所示:

android.support.v7.app.AlertDialog alert = builder.create();

ImageView myView = new ImageView(mContext);
myView.setImageResource(R.drawable.image);

FrameLayout f1 = (FrameLayout) findViewById(android.R.id.custom);
f1.addView(myView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

alert.show();
f1总是获取null,因此获取NullPointerException

如果我像下面这样更改代码,则没有帮助:

FrameLayout f1 = (FrameLayout) alert.findViewById(android.R.id.custom);

网站上有一个关于自定义布局的充气机的类似问题,但情况不同。

您只需添加
setView(视图视图、int-viewspaccingleft、int-viewspaccingtop、int-viewspaccingright、int-viewspaccingbottom)


你能告诉我你到底想要什么吗?你有没有任何图片可以展示你想要的extact UI?我只是想用文档化的方式将视图添加到警报对话框布局中。