如何实现自定义AlertDialog视图在AlertDialog上的Android文档,它给出了在AlertDialog中设置自定义视图的以下指令和示例:如果要显示更复杂的视图,请查找称为“body”的FrameLayout,并将视图添加到其中:FrameLayout fl = (FrameLayout) findViewById(R.id.body);fl.add(myView, new LayoutParams(FILL_PARENT, WRAP_CONTENT));首先,很明显add()是一个错误,应该是addView().我对使用R.id.body的第一行感到困惑。好像是AlertDialog的身体成分.。但我不能只在代码b/c中输入它就会产生编译错误。身体是在哪里定义或分配的?这是我的密码。我试着用setView(findViewById(R.layout.whatever)在建筑工人身上,但不起作用。我想是因为我没有手动充气?AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setTitle("Title")
.setCancelable(false)
.setPositiveButton("Go", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
EditText textBox = (EditText) findViewById(R.id.textbox);
doStuff();
}});FrameLayout f1 = (FrameLayout)findViewById(R.id.body /*CURRENTLY an ERROR*/);f1.addView(findViewById(R.layout.dialog_view));AlertDialog alert = builder.create();alert.show();
3 回答
![?](http://img1.sycdn.imooc.com/545862aa0001f8da02200220-100-100.jpg)
慕村225694
TA贡献1880条经验 获得超4个赞
LayoutInflater inflater = getLayoutInflater();FrameLayout f1 = (FrameLayout)alert.findViewById(android.R.id.body);f1.addView(inflater.inflate(R.layout.dialog_view, f1, false));
- 3 回答
- 0 关注
- 531 浏览
添加回答
举报
0/150
提交
取消