Android的定制PopupWindow /对话Android、PopupWindow

2023-09-12 07:04:14 作者:冋忆妸洧妸嘸

我试图让一个完全自定义对话框或PopupWindow,没有任何默认的Andr​​oid UI控件(标题,背景,按钮,等等)。

这是可能的吗?我花了几个小时寻找这一点,但没有运气......看起来这应该是容易做到的,但我不能找到它。

preferably这将是由膨胀从XML视图,但在这个将只是工作就好了点什么。

感谢。

解决方案

我的步骤了:

创建一个类扩展对话框。 在的onCreate,呼叫的setContentView(X,Y) X 为您R.layout和是R.style.popupStyle(见下文)。 在RES /价值/ style.xml,你需要覆盖默认DialogWindow风格。我尝试只是让有这一个作为其父风格,但仍然没有清除所有默认设置。所以,我检查了Android的Git树,并得到了默认样式,只是复制粘贴它。这是一个:

<样式名称=Theme.Dialog>
    <项目名称=机器人:窗框> @空< /项目>
    <项目名称=机器人:windowTitleStyle> @android:款式/ DialogWindowTitle< /项目>
    <项目名称=机器人:windowBackground> @android:绘制/ panel_background< /项目>
    <项目名称=机器人:windowIsFloating>真< /项目>
    <项目名称=机器人:windowContentOverlay> @空< /项目>
    <项目名称=机器人:windowAnimationStyle> @android:款式/ Animation.Dialog< /项目>
    <项目名称=机器人:windowSoftInputMode> stateUnspecified | adjustPan< /项目>
< /风格> 

您会得到一些错误,只是解决这些问题从官方Android styles.xml和的themes.xml文件复制更多的东西。这是我的styles.xml文件的内容: http://pastebin.com/RRR15YYS

这只是给你一个白色的弹出,没有国界,没有什么。开始定制。 :)

感谢mbaird的把我在正确的轨道。

我需要查找我自己的答案了,我可花了至少10分钟搜索官方Android风格/主题文件,所以在这里,他们是,以供将来参考: styles.xml和themes.xml.

Android使用PopUpWindow

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.

解决方案

Steps I took:

Create a class extending Dialog. In the onCreate, call setContentView(x, y) with x being your R.layout and y being R.style.popupStyle (see below). In your res/values/style.xml, you need to override the default DialogWindow style. I tried just making a style that has this one as its parent, but that still didn't clear all defaults. So I checked the Android git tree and got the default style, and just copy-pasted it. This is the one:

<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>

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.