Android 自定义弹出窗口/对话框
我试图获得一个完全自定义的 Dialog 或 PopupWindow,没有任何默认的 Android UI 控件(标题、背景、按钮等)。
这有可能吗?我花了几个小时寻找这个,但没有运气......看起来这应该很容易实现,但我找不到它。
最好是通过从 XML 扩充视图来实现,但此时任何能正常工作的东西都很好。
谢谢。
I'm trying to get a completely custom Dialog or PopupWindow, without any of the default Android UI controls (title, background, buttons, whatever).
Is this possible at all? I've spent hours searching for this, but no luck... It seems like this should be easily possible, but I can't find it.
Preferably this would be by inflating a View from XML, but at this point anything that would just work would be nice.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我采取的步骤:
setContentView(x, y)
,其中x
是您的 R.layout,y
是 R.style.popupStyle(见下文) )。您会遇到一些错误,只需从官方 Android styles.xml 和 theme.xml 文件中复制更多内容即可解决它们。这是我的 styles.xml 文件的内容: http://pastebin.com/RRR15YYS
这只是给你一个白色弹出窗口,没有边框,什么都没有。开始定制。 :)
感谢 mbaird 让我走上了正确的道路。
[编辑]我需要再次查找我自己的答案,我花了至少十分钟搜索官方的 android 样式/主题文件,所以这里是,以供将来参考:
styles.xml 和 themes.xml。
Steps I took:
setContentView(x, y)
withx
being your R.layout andy
being R.style.popupStyle (see below).You'll get a few errors, just solve them by copying more stuff from the official Android styles.xml and themes.xml files. Here's the contents of my styles.xml file: http://pastebin.com/RRR15YYS
That just gives you a white popup, no borders, nothing. Start customizing. :)
Thanks to mbaird for putting me on the right track.
[edit] I needed to look up my own answer again, and I spent at least ten minutes searching the official android styles/themes files, so here they are, for future reference:
styles.xml and themes.xml.
听起来您正在尝试真正自定义 AlertDialog< /a>.对于您想做的事情,您最好创建自己的类来扩展 对话框,类似于通过编写扩展 活动。
您可以通过在自定义 Dialog 类的 onCreate() 方法中调用 setContentView() 来设置布局 XML,就像在 Activity 中一样。
过去,我遇到了对 AlertDialogs 的自定义程度的限制,并且我刚刚实现了自己的 Dialog 类以获得我需要的自定义级别。
It sounds like you are trying to really customize an AlertDialog. For what you are wanting to do you may be better off just creating your own class that extends Dialog, similar to how you create activities by writing a class that extends Activity.
You can set the layout XML by calling setContentView() inside the onCreate() method of your custom Dialog class, just like you would in an Activity.
I've run into limitations on how much you can customize AlertDialogs in the past, and I've just implemented my own Dialog classes to get the level of customization that I needed.