我想在用户触摸ImageVIEw时创建一个d出窗口.我看了一下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存在问题.
所以问题是,上面有什么问题,还有更好的方法来创建自定义d出窗口(可能通过使用Dialog类或扩展它)?
注意:我只是在这个例子中使用TextVIEw作为测试,我想为我的实际d出窗口添加更复杂的东西.
解决方法 一个选项是使用对话框主题创建一个Activity并设置它的样式:<activity androID:theme="@androID:style/theme.Dialog">
有关更多信息,请参见applying themes.
总结以上是内存溢出为你收集整理的自定义AlertDialog – android.R.id.custom的问题全部内容,希望文章能够帮你解决自定义AlertDialog – android.R.id.custom的问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)