【发布时间】:2015-08-16 12:53:33
【问题描述】:
文档是这样说的:
如果要显示更复杂的视图,请查看 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);
网站上有一个关于自定义布局的充气机的类似问题,但情况不同。
【问题讨论】:
-
你能说出你到底想要什么吗,你有什么图片可以说明你想要的确切 UI
-
我只想使用文档化的方式将视图添加到警报对话框布局中。