Android MaterialAlertDialogBuilder修改按钮属性
作者:九狼 时间:2021-12-20 06:56:19
编写按钮属性
首先再values/themes 或者values/style在文件下编写按钮属性
buttonBarPositiveButtonStyle
对应着确认按钮
buttonBarNegativeButtonStyle
对应着取消按钮
<style name="AlertDialogTheme">
<item name="buttonBarPositiveButtonStyle">@style/Alert.Button.Positive</item>
<item name="buttonBarNegativeButtonStyle">@style/Alert.Button.Negative</item>
</style>
<style name="Alert.Button.Positive" parent="Widget.MaterialComponents.Button.TextButton">
<item name="backgroundTint">@color/colorPrimary</item>
<item name="rippleColor">@color/colorAccent</item>
<item name="android:textColor">@android:color/white</item>
<item name="android:textSize">14sp</item>
<item name="android:textAllCaps">false</item>
<item name="android:layout_marginStart">3dp</item>
</style>
<style name="Alert.Button.Negative" parent="Widget.MaterialComponents.Button.TextButton">
<item name="backgroundTint">@color/colorPrimary</item>
<item name="rippleColor">@color/colorAccent</item>
<item name="android:textColor">@android:color/white</item>
<item name="android:textSize">14sp</item>
</style>
Dialog 风格设置
为Dialog设置风格 new MaterialAlertDialogBuilder(getContext(), R.style.AlertDialogTheme)
AlertDialog.Builder alertDialogBuilder = new MaterialAlertDialogBuilder(getContext(), R.style.AlertDialogTheme)
.setTitle("添加设备")
.setPositiveButton(
"确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
}
})
.setNegativeButton("取消", null);
alertDialogBuilder.show();
效果图
buttonBarPositiveButtonStyle
对应着确认按钮
来源:https://juejin.cn/post/7080465081984778276
标签:Android,MaterialAlertDialogBuilder,修改,按钮属性
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java concurrency集合之 CopyOnWriteArrayList_动力节点Java学院整理
2022-10-27 05:03:36
![](https://img.aspxhome.com/file/2023/8/104048_0s.png)
C#文件操作的简单实例
2021-12-14 16:50:40
Java中JUC 的 Exchange 交换器详情
2023-09-17 18:46:40
![](https://img.aspxhome.com/file/2023/2/76252_0s.webp)
Java Code Cache满导致应用性能降低问题解决
2021-06-18 18:17:56
Android使用Retrofit实现自定义Converter解析接口流程详解
2022-12-30 23:19:38
springboot搭建访客管理系统的实现示例
2023-09-02 13:10:41
![](https://img.aspxhome.com/file/2023/3/58463_0s.png)
Java数据结构与算法之选择排序(动力节点java学院整理)
2022-06-23 12:28:24
![](https://img.aspxhome.com/file/2023/5/93065_0s.png)
C#实现跑马灯效果的示例代码
2022-06-10 07:12:40
![](https://img.aspxhome.com/file/2023/5/82155_0s.png)
C#生成防伪码的思路及源码分享
2022-10-27 03:53:41
![](https://img.aspxhome.com/file/2023/2/104292_0s.png)
C#抽象类和接口的区别分析
2023-11-09 13:56:21
java中的JsonSerializer用法,前后端单位转换必备
2022-05-01 07:58:48
![](https://img.aspxhome.com/file/2023/4/64904_0s.jpg)
SpringBoot整合Log4j2及配置步骤
2023-10-27 10:50:16
![](https://img.aspxhome.com/file/2023/8/103808_0s.jpg)
Android实现Path平滑的涂鸦效果实例
2023-12-11 23:07:45
![](https://img.aspxhome.com/file/2023/3/97863_0s.jpg)
在项目中直接使用hystrix的流程分析
2021-10-22 01:55:21
![](https://img.aspxhome.com/file/2023/8/73048_0s.jpg)
C#日期格式字符串的相互转换操作实例分析
2021-09-01 10:06:56
Java实现斗地主与猜数字游戏详细流程
2022-02-04 07:02:48
![](https://img.aspxhome.com/file/2023/5/94305_0s.png)
用Java设计模式中的观察者模式开发微信公众号的例子
2023-01-17 05:30:58
![](https://img.aspxhome.com/file/2023/5/88045_0s.jpg)
Android实现MVVM架构数据刷新详解流程
2023-07-05 13:33:41
![](https://img.aspxhome.com/file/2023/5/92615_0s.png)
MyBatis拦截器原理探究
2021-07-18 23:24:19
Android仿天猫横向滑动指示器功能的实现
2022-10-09 16:53:58
![](https://img.aspxhome.com/file/2023/2/101822_0s.jpg)