修改 AlertDialog 中按钮颜色的方法







AlertDialog dialog = builder.create();
dialog.getButton(dialog.BUTTON_POSITIVE).setTextColor(Color.BLACK);
dialog.getButton(dialog.BUTTON_NEGATIVE).setTextColor(Color.BLACK);
dialog.setCanceledOnTouchOutside(false);//禁止点击 dialog 外部取消弹窗



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
修改框架层的AlertDialog的确认和取消按钮的文字颜色,你可以尝试以下步骤: 1. 创建一个自定义的AlertDialog主题,在其设置按钮的文字颜色。在你应用的 `res/values/styles.xml` 文件添加以下代码: ```xml <style name="CustomAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="android:buttonBarButtonStyle">@style/CustomButtonBarButtonStyle</item> </style> <style name="CustomButtonBarButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog"> <item name="android:textColor">@color/custom_button_text_color</item> </style> ``` 2. 在你的 `res/values/colors.xml` 文件定义你想要的自定义按钮文字颜色: ```xml <color name="custom_button_text_color">#FF0000</color> ``` 3. 在使用AlertDialog的地方,将主题设置为你自定义的主题。例如,在Activity使用: ```java AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.CustomAlertDialogTheme)); builder.setTitle("Title") .setMessage("Message") .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // 点击确认按钮的逻辑 } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // 点击取消按钮的逻辑 } }); AlertDialog dialog = builder.create(); dialog.show(); ``` 通过以上步骤,你可以自定义AlertDialog的确认和取消按钮的文字颜色。记得将 `custom_button_text_color` 替换为你想要的颜色值。希望这能帮到你!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值