如何改变警告对话框标题分颜色的android [英] How to change alert dialog header divider color android

查看:216
本文介绍了如何改变警告对话框标题分颜色的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发小型机器人application.and我想的标题标题提示对话框风格或改变颜色分。我搜索一下这个问题,我想很多人寻找this.But我仍然没有能够找到合适的解决方案。我想改变这个如下。

I am developing small android application.and I wanted to style or change divider color of header title in alert dialog. I search about this question and I think lot of people searching for this.But I am still not able to find out right solution. I want to change this following.

推荐答案

实际上,你可以通过一个非常简单的黑客更改AlertDialog标题颜色:

You can actually change color of AlertDialog title by a very simple hack:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆