如何更改 AlertDialog 标题的颜色及其下方线条的颜色 [英] How can I change the color of AlertDialog title and the color of the line under it

查看:28
本文介绍了如何更改 AlertDialog 标题的颜色及其下方线条的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此命令更改了 AlertDialog 标题的颜色

alert.setTitle( Html.fromHtml("<font color='#FF7F27'>设置 IP 地址</font>"));

但是我想改变标题下出现的线条的颜色;我怎样才能做到这一点 ?

注意:我不想使用自定义布局

解决方案

不幸的是,这不是一项特别容易完成的任务..>

I changed the color of an AlertDialog title using this command

alert.setTitle( Html.fromHtml("<font color='#FF7F27'>Set IP Address</font>"));

But I want to change the color of the line that appear under the title; how can I do that ?

Note: I don't want to use a custom layout

解决方案

Unfortunately, this is not a particularly simple task to accomplish. In my answer here, I detail how to adjust the color of a ListSeparator by just checking out the parent style used by Android, creating a new image, and creating a new style based on the original. Unfortunately, unlike with the ListSeparator's style, AlertDialog themes are internal, and therefore cannot be referenced as parent styles. There is no easy way to change that little blue line! Thus you need to resort to making custom dialogs.

If that just isn't your cup of tea... don't give up! I was very disturbed that there was no easy way to do this so I set up a little project on github for making quickly customized holo-style dialogs (assuming that the phone supports the Holo style). You can find the project here: https://github.com/danoz73/QustomDialog

It should easily enable going from boring blue to exciting orange!

The project is basically an example of using a custom dialog builder, and in the example I created a custom view that seemed to cater to the IP Address example you give in your original question.

With QustomDialog, in order to create a basic dialog (title, message) with a desired different color for the title or divider, you use the following code:

private String HALLOWEEN_ORANGE = "#FF7F27";

QustomDialogBuilder qustomDialogBuilder = new QustomDialogBuilder(v.getContext()).
    setTitle("Set IP Address").
    setTitleColor(HALLOWEEN_ORANGE).
    setDividerColor(HALLOWEEN_ORANGE).
    setMessage("You are now entering the 10th dimension.");

qustomDialogBuilder.show();

And in order to add a custom layout (say, to add the little IP address EditText), you add

setCustomView(R.layout.example_ip_address_layout, v.getContext())

to the builder with a layout that you have designed (the IP example can be found in the github). I hope this helps. Many thanks to Joseph Earl and his answer here.

这篇关于如何更改 AlertDialog 标题的颜色及其下方线条的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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