我正在尝试获得一个完全自定义的 Dialog 或 PopupWindow,没有任何默认的 Android UI 控件(标题、背景、按钮等).
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.
最好是通过从 XML 扩展视图来实现,但在这一点上,任何可以正常工作的东西都会很好.
Preferably this would be by inflating a View from XML, but at this point anything that would just work would be nice.
谢谢.
我采取的步骤:
setContentView(x, y)
,其中 x
是您的 R.layout,y
是 R.style.popupStyle(见下文).setContentView(x, y)
with x
being your R.layout and y
being R.style.popupStyle (see below).<style name="Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowTitleStyle">@android:style/DialogWindowTitle</item>
<item name="android:windowBackground">@android:drawable/panel_background</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
您会遇到一些错误,只需从官方 Android 的 styles.xml 和 Themes.xml 文件中复制更多内容即可解决这些错误.这是我的 styles.xml 文件的内容:http://pastebin.com/RRR15YYS
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. :)
感谢 mbaird 让我走上正轨.
Thanks to mbaird for putting me on the right track.
[edit] 我需要再次查找自己的答案,并且我花了至少十分钟搜索官方的 android 样式/主题文件,所以在这里,以供将来参考:styles.xml 和 themes.xml.
[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.
这篇关于Android 自定义 PopupWindow/Dialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!