修改 Dialog NegativeButton 字体颜色
时间: 2024-09-13 17:12:17 浏览: 81
在Android中,如果你想要修改Dialog中的NegativeButton(负按钮)字体颜色,你可以通过自定义DialogFragment或者直接操作AlertDialog的样式。这里是一个简单的示例,假设你已经有了一个`AlertDialog.Builder`实例:
```java
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(false); // 设置是否可以取消
// 创建一个新的StyleableAttribute对象来引用颜色资源
int colorResId = R.color.your_custom_color; // 替换为你想设置的颜色ID
// 使用setView()方法添加自定义布局,然后找到NegativeButton并设置其颜色
View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_your_layout, null);
TextView negativeButton = (TextView) dialogView.findViewById(R.id.your_negative_button_id);
negativeButton.setTextColor(Color.parseColor("#" + Integer.toHexString(colorResId))); // 设置颜色
builder.setView(dialogView);
// 创建并显示对话框
AlertDialog alertDialog = builder.create();
alertDialog.show();
```
在这个例子中,你需要将`your_custom_color`替换为你应用中的实际颜色资源ID,并确保能找到对应的`TextView`元素作为NegativeButton。
阅读全文
相关推荐


















