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

Android 对话框背景填充的默认颜色是什么?,android,android-layout,Android,Android Layout,当AndroidAlertDialog显示时,此对话框周围的背景会变得更暗。这可能是通过首先用半透明的颜色填充整个屏幕,然后在上面放置一个对话框来实现的 我的问题是:背景填充的默认颜色是什么 #88666666 //looks close, but not enough 试试这个颜色代码#80000000@activity如果您查看AppCompat的对话框,我相信它正在使用: <color name="dim_foreground_disabled_material_dark">

当Android
AlertDialog
显示时,此对话框周围的背景会变得更暗。这可能是通过首先用半透明的颜色填充整个屏幕,然后在上面放置一个对话框来实现的

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

#88666666 //looks close, but not enough

试试这个颜色代码#80000000@activity

如果您查看AppCompat的对话框,我相信它正在使用:

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

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

试试看效果非常好

onCreate()中

清单中

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

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 name="color_trans">#99000000</color>

假的
真的
假的
假的
@颜色/颜色转换
@空的
真的
color.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 name="color_trans">#99000000</color>
#99000000

面向未来读者:

作者称之为对话框背景填充的问题在“材料设计规范”中称为“Scrim”

因此,斯克里姆的颜色根据是

颜色:#000000

不透明度:32%


更改适用于对话的应用程序主题。它可能不完全相同,但抽屉布局的默认scrim颜色为#99000000。您可以在androidx DroperLayout类中找到它,它有:private static final int DEFAULT\u SCRIM\u COLOR=0x99000000;即#52000000