android - 如何更改警报对话框标题分隔线颜色android

标签 android colors dialog styles android-alertdialog

我想在警报对话框中设置样式或更改标题标题的分隔线颜色。我搜索了这个问题,我想很多人都在搜索这个。但我仍然无法找到正确的解决方案。我想更改以下内容。 Blue header divider

最佳答案

实际上,您可以通过非常简单的 hack 更改 AlertDialog 标题的颜色:

public static void brandAlertDialog(AlertDialog dialog) {
    try {
        Resources resources = dialog.getContext().getResources();
        int color = resources.getColor(...); // your color here

        int alertTitleId = resources.getIdentifier("alertTitle", "id", "android");
        TextView alertTitle = (TextView) dialog.getWindow().getDecorView().findViewById(alertTitleId);
        alertTitle.setTextColor(color); // change title text color

        int titleDividerId = resources.getIdentifier("titleDivider", "id", "android");
        View titleDivider = dialog.getWindow().getDecorView().findViewById(titleDividerId);
        titleDivider.setBackgroundColor(color); // change divider color
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

关于android - 如何更改警报对话框标题分隔线颜色android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15271500/

相关文章:

android - AVDMANAGER -> 错误 : Invalid --tag default for the selected package

colors - 在 RGB 和一个整数/浮点值之间转换

wpf - 彩色动画内容演示器

java - 如何找到完整显示窗口标题的最小宽度

android - 如何在android应用程序中自动填充编辑文本?

java - 纹理 View 中的 CameraX 在横向模式下反转 90 度

android - 在布局中放置 3 个图像

Java for循环迭代并列出颜色

javascript - 如何将按钮传递到 Jquery 函数中?

c++ - win32 - .dll 中的对话框