AlertDialog更改按钮颜色

来源:互联网 发布:淘宝收费推广工具 编辑:程序博客网 时间:2024/06/10 20:35

如果没有调用Show 方法AlertDialog.getButton(DialogInterface.BUTTON_POSITIVE) 为 null。AlertDialog 的逻辑是 show()方法 中初始化了 AlertDialog 上面的控件,然后展示出来,所以在 show()方法 执行之后才能得到 button。

  final AlertDialog alertDialog = new AlertDialog.Builder(this).setTitle("sdd").setPositiveButton("kk",null).setNegativeButton("取消",null).setNeutralButton("dd",null).create();alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {            @Override            public void onShow(DialogInterface dialog) {                Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);                button.setTextColor(Color.GREEN);            }        });alertDialog.show();

不用费劲的去改主题了

阅读全文
0 0
原创粉丝点击