android - 更改对话框的背景暗色出现在 android 中

标签 android dialog android-theme

您好,我必须将主题中对话框的暗色更改为白色,以便通过设置 layoutParams.dimAmount = 0.5f;我可以在对话框背景中得到模糊的白色。
我正在使用

<style name="MyDialog" parent="@android:style/Theme.Holo.Light.Dialog">
            <item name="android:windowBackground">@color/dialog_dim_background</item>
    </style>

以及以下引用资料
How do I create a transparent Activity on Android?
Custom screen dim with Dialog

最佳答案

这是一个非常古老的问题,但我想为其添加 n 个答案。我遇到了同样的问题并在谷歌上搜索了很多。然后想出了我自己的解决方案。

首先,我用这个完全消除了暗淡

dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

然后我打开我的布局(它是RelativeLayout)并将这个 View 放入其中作为最后一个元素

<View
        android:id="@+id/shade"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/primaryShadow"
        android:visibility="invisible"/>

背景色是您想要用作暗色的颜色。如您所见,它在创建时是不可见的。因此,在将对话框启动到 View.VISIBLE 之前,您需要在 Activity 中找到它并设置它的可见性。取消对话框时,再次将其设置为 View.INVISIBLE。就是这样。

关于android - 更改对话框的背景暗色出现在 android 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23991424/

相关文章:

android - 我们应该经常在 android 中与数据库存储交互吗?

android - 与外部可触摸的对话

android - Android在MaterialDialog中对齐中心或对齐右标题和消息

android - 使所有 View 透明以仅看到主题背景图像

android - 将 WebView 中的文本方向设置为 RTL

java - 使用 JSON 解析获取 OpenWeathermapApi 数据

android - 比特桶 : The requested URL returned error: 402

android: 对话框,取消按钮

android - 将 CardView 高程重置为默认值(静止高程)