Android Custom PopupWindow/Dialog

后端 未结 2 704
感情败类
感情败类 2020-12-02 12:46

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

2条回答
  •  醉话见心
    2020-12-02 13:08

    Steps I took:

    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:

    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.

提交回复
热议问题