自定义AlertDialog – android.R.id.custom的问题

自定义AlertDialog – android.R.id.custom的问题,第1张

概述我确定我错过了这里的重点,所以我希望有人可以解释. 我想在用户触摸ImageView时创建一个d出窗口.我看了一下AlertDialog,文档说…… If you want to display a more complex view, look up the FrameLayout called “custom” and add your view to it: ……使用以下代码…… Frame 我确定我错过了这里的重点,所以我希望有人可以解释.

我想在用户触摸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的问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1124139.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存