Android自定义PopupWindow /对话框 [英] Android Custom PopupWindow/Dialog

查看:390
本文介绍了Android自定义PopupWindow /对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获得一个完全自定义的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充实一个View,但在这一点上,任何可以工作的东西都会很好。

Preferably this would be by inflating a View from XML, but at this point anything that would just work would be nice.

谢谢。

推荐答案

我采取的步骤:


  1. 创建一个扩展对话框

  2. 在onCreate中,调用 setContentView(x,y) x 是您的R.layout和 y 是R.style.popupStyle(见下文)。

  3. 在res / values / style.xml中,需要覆盖默认的DialogWindow样式。我试着做一个风格,把这个作为它的父母,但仍然没有清除所有默认值。所以我检查了Android git树,并获得了默认的样式,只是复制粘贴它。这是一个:

  1. Create a class extending Dialog.
  2. In the onCreate, call setContentView(x, y) with x being your R.layout and y being R.style.popupStyle (see below).
  3. 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>

您会收到一些错误,只需通过从官方的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.

我需要看再次回到我自己的答案,我花了至少十分钟的时间搜索官方的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 /对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆