gpt4 book ai didi

android - 设置对话框标题栏的背景颜色?

转载 作者:IT老高 更新时间:2023-10-28 23:11:41 26 4
gpt4 key购买 nike

我正在创建一个派生自 Dialog 的类。对话框的标题栏看起来非常漂亮,它是一种深灰色,有点透明。有没有办法设置标题栏背景的颜色?灰色很酷,但我想将它设置为一些自定义颜色。我认为这是不可能的,我认为我需要提供自己的可拉伸(stretch)背景对话框资源。对吗?

谢谢

最佳答案

使用下面的代码:

final Dialog mailDialog = new Dialog(MainActivity.this);
mailDialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_box);

并在drawable文件夹中创建一个自定义对话框xml,如下所示:

dialog_box.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />

<gradient
android:angle="-90"
android:centerColor="#660D1E4A"
android:endColor="#66011444"
android:startColor="#66505E7F"
android:type="linear"
/>

<stroke
android:dashGap="0dp"
android:dashWidth="0dp"
android:width="1dp"
android:color="#ffffffff" />

</shape>

希望对你有所帮助。

关于android - 设置对话框标题栏的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2391652/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com