我确定我错过了这里的重点,所以我希望有人可以解释.
我想在用户触摸ImageView时创建一个弹出窗口.我看了一下AlertDialog,文档说……
If you want to display a more complex view,look up the FrameLayout called “custom” and add your view to it:
……使用以下代码……
FrameLayout fl = (FrameLayout) findViewById(android.R.id.custom);
fl.addView(myView,new LayoutParams(MATCH_PARENT,WRAP_CONTENT));
所以作为测试我在onCLick()方法中尝试了以下内容……
TextView tv = new TextView(this);
tv.setText("Hello World");
FrameLayout customFrameLayout = (FrameLayout) findViewById(android.R.id.custom);
customFrameLayout.addView(tv,new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
上面我调用addView()的最后一行抛出一个NullPointerException,这让我觉得android.R.id.custom存在问题.
所以问题是,上面有什么问题,还有更好的方法来创建自定义弹出窗口(可能通过使用Dialog类或扩展它)?
注意:我只是在这个例子中使用TextView作为测试,我想为我的实际弹出窗口添加更复杂的东西.