AndroidStudio无法更改AlertDialogJAVA中按钮的颜色。
创始人
2024-10-11 20:30:08
0

在AlertDialog中,如果要自定义按钮的颜色,可以采用如下代码:

AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("Message")
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
               // do something
           }
       })
       .setNegativeButton("No", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
               // do something
           }
       });

AlertDialog alertDialog = builder.create();
alertDialog.show();

Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setTextColor(getResources().getColor(R.color.colorAccent));

Button negativeButton = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
negativeButton.setTextColor(getResources().getColor(R.color.colorPrimary));

其中,首先需要创建一个AlertDialog.Builder实例,然后通过设置其按钮的颜色即可。使用getButton()方法来获取对应的按钮,然后通过setTextColor()方法来设置颜色。

需要注意的是,颜色值需要从资源文件中获取,例如从color.xml文件中获取颜色值,如上面的代码所示。

相关内容

热门资讯

这一现象值得深思!we pok... 这一现象值得深思!we poker辅助器v3.3,impoker辅助,法门教程(真的有挂)-哔哩哔哩...
透视好牌!德普之星有辅助软件吗... 透视好牌!德普之星有辅助软件吗,德普之星怎么设置埋牌(透视)确实有挂(有挂教学)-哔哩哔哩1、德普之...
今日!广东雀神智能插件需要付费... 今日!广东雀神智能插件需要付费吗,小程序微乐斗地主辅助,办法教程(有挂方略)-哔哩哔哩1、广东雀神智...
透视透视挂!德普之星透视辅助软... 透视透视挂!德普之星透视辅助软件是真的吗,德普之星透视辅助软件(透视)竟然有挂(有挂教学)-哔哩哔哩...
据报道!天天贵阳破解版,wep... 据报道!天天贵阳破解版,wepoker插件功能辅助器,方式教程(果真有挂)-哔哩哔哩;在进入wepo...
透视中牌率!德普之星辅助器ap... 透视中牌率!德普之星辅助器app,德普之星的辅助工具介绍(透视)竟然是真的挂(有人有挂)-哔哩哔哩1...
截至发稿!丰城双剑辅助器,小程... 截至发稿!丰城双剑辅助器,小程序雀神雀神智能插件,总结教程(详细教程)-哔哩哔哩1、下载好小程序雀神...
透视脚本!德普辅助器怎么用,德... 透视脚本!德普辅助器怎么用,德普之星透视软件免费入口官网(透视)一直是有挂(有挂解密)-哔哩哔哩1、...
为了进一步!多乐破解游戏盒子破... 为了进一步!多乐破解游戏盒子破解版,微乐小程序自建房辅助下载,机巧教程(有挂秘笈)-哔哩哔哩1、微乐...
透视脚本!德普之星怎么开辅助,... 透视脚本!德普之星怎么开辅助,德普之星怎么开辅助(透视)竟然真的是有挂(有挂功能)-哔哩哔哩一、德普...