如何在警报对话框中更改按钮的颜色 [英] How to change color of Button in Alert Dialog

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

问题描述

这是我用于创建对话框的代码,

Here my code for create Dialog,

builder.setMessage(msg).setNeutralButton("Dismiss",dialogClickListener)
                       .setPositiveButton("Edit", dialogClickListener)
                       .setNegativeButton("Delete", dialogClickListener).show();

是否可以用蓝色而不是红色显示关闭?

Is it possible to display dismiss in blue color rather than red?

推荐答案

首先,从构建器创建AlertDialog:

First, create AlertDialog from builder:

AlertDialog dialog = builder.create();

然后您可以找到按钮并更改颜色:

Then you can find your button and change color:

dialog.show(); //Only after .show() was called
dialog.getButton(dialog.BUTTON_NEGATIVE).setTextColor(your_color);
dialog.getButton(dialog.BUTTON_POSITIVE).setTextColor(your_color);
dialog.getButton(dialog.BUTTON_NEUTRAL).setTextColor(your_color);

在此使用下一个方法:

void setTextColor (int color)
     Sets the text color for all the states (normal, selected, focused) to be this color.
Parameters
     color  int: A color value in the form 0xAARRGGBB. Do not pass a resource ID. To get a color value from a resource ID, call getColor.

这篇关于如何在警报对话框中更改按钮的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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