更改 AlertDialog 中的按钮颜色 [英] Change button color in AlertDialog

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

问题描述

如何在 Android 的 AlertDialog 中更改按钮的颜色?

How can I change the color of the button(s) in an AlertDialog in Android?

推荐答案

我就是这样做的.

AlertDialog.Builder customBuilder = new AlertDialog.Builder(new ContextThemeWrapper(this,android.R.style.Theme_Dialog));

customBuilder.setTitle(R.string.popup_error_title);
customBuilder.setNegativeButton("Exit application", new DialogInterface.OnClickListener() {  
    public void onClick(DialogInterface dialog, int which) {  
        MyActivity.this.finish();
    }  
});

AlertDialog dialog = customBuilder.create();
dialog.show();

Button b = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);

if(b != null) {
    b.setBackgroundDrawable(getResources().getDrawable(R.drawable.my_button));
}

我在这里找到了可绘制的

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

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