如何创建一个完全自定义的对话/弹出窗口中的Andr​​oid(更改覆盖颜色和对话窗口布局)弹出、自定义、创建一个、布局

由网友(鬼守尸)分享简介:我想完全重新皮肤的默认对话组件的An​​dr​​oid。具体来说,我想做到这一点:I would like to completely re-skin the default dialogue component in Android. Specifically I would like to do this:更​...

我想完全重新皮肤的默认对话组件的An​​dr​​oid。具体来说,我想做到这一点:

I would like to completely re-skin the default dialogue component in Android. Specifically I would like to do this:

更​​改半透明叠加的背景从默认的黑色半透明的白色。

Change the semi-transparent overlay background from the default black to a semi-transparent white.

更​​改的对话窗口 删除默认窗框架边框, 并用一个布局代替它 在XML中定义的(它只是将是 一个无国界的图形与浮动 按钮。没有实际的框架。)

Change the Dialogue window by removing the default windowed frame border, and replacing it with a layout defined in XML (it's just going to be a borderless graphic with floating buttons. no actual frame.)

我看到有关对话框内创建自定义布局(如http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application),但我还没有看到关于改变颜色的叠加和/或完全自定义的对话窗口弹出,更使之成为一个覆盖无窗口任何事情。

I have seen tutorials about creating a custom layout for within the dialogue box (e.g. http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application), but I haven't seen anything regarding changing the colour of the overlay and/or completely customizing the dialogue window that pops up and turning it more into an overlay with no "window".

推荐答案

我已经解决了这个问题,通过以下步骤创建自己的自定义弹出的覆盖与自定义颜色的半透明叠加背景:

I've solved this problem and created my own custom popup overlay with a custom coloured semi-transparent overlay background using the following steps:

1 - 你的RES /价值/文件夹中创建一个新的XML文件,并将其命名为styles.xml

1 - Create a new xml file in your res/values/ folder and name it styles.xml

2 - 在这里你将定义您的对话框属性。下面是我的样子。如果要替换默认半透明的黑色覆盖,显示在屏幕上,你必须设置 windowIsFloating 为假,并修改您的布局是什么颜色的背景你想。这是我的文件下,我已经用:

2 - Here is where you will define your dialog properties. Here is what mine looks like. If you want to replace the default semi-transparent black overlay that shows over the screen, you have to set windowIsFloating to false, and modify the background of your layout to be whatever colour you want. Here is my file below that I've used:

< XML版本=1.0编码=UTF-8> <资源>   <样式名称=CustomDialogTheme   父=@安卓风格/ Theme.Dialog> <项目   名字=机器人:windowBackground> @色/ transparent_white< /项目>   <项目名称=机器人:windowIsFloating>假< /项目> <项目   名字=机器人:windowNoTitle>真< /项目> < /风格>   < /资源>

<?xml version="1.0" encoding="utf-8"?> <resources> <style name="CustomDialogTheme" parent="@android:style/Theme.Dialog"> <item name="android:windowBackground">@color/transparent_white</item> <item name="android:windowIsFloating">false</item> <item name="android:windowNoTitle">true</item> </style> </resources>

3 - 回到你的java code,创建对话框对象时,使用经过双方的背景和主题的构造。例如。 myDialog =新的对话框(这一点,R.style.CustomDialogTheme); (CustomDialogTheme是我在styles.xml从第2步中指定的名称属性)

3 - Back in your java code, when creating the dialog object, use the constructor that passes both the context AND the theme. Eg. myDialog = new Dialog(this, R.style.CustomDialogTheme); (CustomDialogTheme is the name attribute I specified in the styles.xml from step 2)

4 - 只需设置对话框对象的内容,以任何布局,你希望你的对话框看起来像。例如。 myDialog.setContentView(R.layout.my_custom_overlay); 如果你想显示在屏幕中央的对话框中,设置它的根元素的安卓layout_gravity 中心

4 - Simply set your dialog objects content view to whatever layout you want your dialog to look like. Eg. myDialog.setContentView(R.layout.my_custom_overlay); If you want your dialog to appear at the center of the screen, set its root element's android:layout_gravity to center

阅读全文

相关推荐

最新文章