首页 > 解决方案 > DialogFragment 更改阴影(蒙版)颜色(不是对话框内容)

问题描述

我正在使用 DialogFragment 构建一个对话框,我需要更改阴影(蒙版)的颜色,它是透明的并且始终围绕主对话框内容。其实网上几乎所有的答案都是改对话框颜色,但是我需要把阴影颜色从透明黑改成其他。有没有办法做到这一点?

图片:

在此处输入图像描述

标签: androiddialogfragment

解决方案


如果您只想更改背景的 alpha,那么您可以android:backgroundDimAmount像我一样轻松创建带有属性的样式

<style name="CustomAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:backgroundDimAmount">0.5</item>
</style>

值范围为 0-1,然后在 AlertDialog 中将样式传递为

AlertDialog dialog = new AlertDialog.Builder(this, R.style.CustomAlertDialogStyle)
            .setTitle("Title").setMessage("message").create();
dialog.show();

但是,如果您也想更改背景颜色,那么您可以尝试@Lee Han Kyeol https://stackoverflow.com/a/29482234/5002610给出的这项工作, 我希望这能解决您的问题。


推荐阅读