Android的对话框 - 自定义背景,而不是调光或模糊 [英] Android Dialog - Custom background instead of dimming or blurring

查看:367
本文介绍了Android的对话框 - 自定义背景,而不是调光或模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建自己的自定义对话框,它工作正常,但我想改变暗淡的背景,自定义模式(例如图像文件或XML形状)。我怎样才能做到这一点?结果
请注意,我不想改变调光的强度,但我只是想,这种调光用一个模式取代

I have created my own custom dialog and it works fine but I want to change dimmed background to a custom pattern (for example an image file or a xml shape). How can I achieve that?
Note that I do not want to change intensity of dimming but I just want, this dimming be replaced with a pattern

推荐答案

我发现了一个办法解决这个问题,我这派生从@vipul米塔尔的答案,结果
我应该设置对话框主题如下:

I found a workaround for this problem, I derived this from @vipul mittal answer,
I should set dialog theme as following:

<item name="android:windowIsFloating">false</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>

通过这个主题我的对话将是:

With this theme my dialog will be:


  • 全屏,因为 windowIsFloating 设置为

  • 周边地区是完全透明的,因为 windowBackground 设置为 @android:彩色/透明

  • full screen because windowIsFloating is set to false
  • surrounding area is fully transparent because windowBackground is set to @android:color/transparent

现在我应该换我对话框XML布局与内容,发挥周边地区作用的包装,在这种情况下,我选择的FrameLayout 此:

Now I should wrap my dialog xml layout contents with a wrapper that plays surrounding area role, in this case I have picked FrameLayout for this:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/dialog_back"> <!-- this is surrounding area drawable -->

    <!-- dialog contents goes here -->

</FrameLayout>

下面是我的最后一个对话框的截图:结果

Here is a screenshot of my final dialog:

这篇关于Android的对话框 - 自定义背景,而不是调光或模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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