对话框背景填充的默认颜色是什么?

22

当Android AlertDialog弹出时,该对话框周围的背景会变暗。这可能是通过先用半透明颜色填充整个屏幕,然后在其上方放置对话框来实现的。

我的问题是:那个背景填充的默认颜色是什么?

#88666666 //looks close, but not enough

将您的应用程序主题更改为适合对话框。 - Gopi Krishna
它可能不完全相同,但DrawerLayout的默认遮罩颜色为#99000000。您可以在androidx DrawerLayout类中找到它,其中包括: private static final int DEFAULT_SCRIM_COLOR = 0x99000000; - chef
4个回答

15

针对未来的读者:

问题作者所称的对话框背景填充,在 Material Design 规范中被称为Scrim

因此,根据Material Design规范,Scrim 的颜色为:

颜色:#000000

不透明度:32%

    <color name="background">#52000000</color>

3

如果你检查 AppCompat 的对话框,我认为它使用的是:

<color name="dim_foreground_disabled_material_dark">#80bebebe</color>
<color name="dim_foreground_disabled_material_light">#80323232</color>

然而在我的测试中,我认为它是#99000000(不透明度为62%的黑色)。


0

试一下!它非常好用!

onCreate()

final int baseAlpha = (0x99000000) >>> 24;
layout.setBackgroundColor(baseAlpha);

清单文件

    <activity
        android:name=".ui.web.WebPopupActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.TransparentWebPopup" />

in style.xml

  <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowEnableSplitTouch">false</item>
    <item name="android:splitMotionEvents">false</item>
</style>

<style name="AppTheme.TransparentWebPopup" parent="AppTheme.NoActionBar">
    <item name="android:windowBackground">@color/color_trans</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowIsTranslucent">true</item>

</style>

color.xml

 <color name="color_trans">#99000000</color>

-2

尝试使用这个颜色代码 #80000000@activity


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接