android - 在 AlertDialog 中更改按钮颜色

标签 android button colors dialog alert

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

最佳答案

这就是我的做法。

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));
}

我找到了可绘制的 here

关于android - 在 AlertDialog 中更改按钮颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4095758/

相关文章:

java - 如何修复这些丢失的库?

java - 单击通知不会打开提到的 Activity

Flutter:如何修复轮廓按钮并为其添加边框和颜色?

python - Matplotlib:从条形图中获取颜色和 x/y 数据

带有叠加层的 Android 可缩放/可滚动 ImageView

android - 如何在 Android TV 应用程序中设置画中画 (PiP) 的位置?

javascript - D3 从包含名称的字符串数组创建按钮

html - 为什么我的 NEXT 和 PREVIOUS 按钮位于屏幕的右侧而不是底部

css - 圆形按钮CSS

c# - WPF 数据网格在文本更改时更改颜色