我的应用程序中有很多警报对话框.这是默认布局,但我在对话框中添加正负按钮.因此按钮获得Android 5(绿色)的默认文本颜色.我试图改变它但没有成功.知道如何改变文字颜色吗?
My Custom对话框:
public class MyCustomDialog extends AlertDialog.Builder {
public MyCustomDialog(Context context,String title,String message) {
super(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View viewDialog = inflater.inflate(R.layout.dialog_simple, null, false);
TextView titleTextView = (TextView)viewDialog.findViewById(R.id.title);
titleTextView.setText(title);
TextView messageTextView = (TextView)viewDialog.findViewById(R.id.message);
messageTextView.setText(message);
this.setCancelable(false);
this.setView(viewDialog);
} }
Run Code Online (Sandbox Code Playgroud)
创建对话框:
MyCustomDialog builder = new MyCustomDialog(getActivity(), "Try Again", errorMessage);
builder.setNegativeButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
...
}
}).show();
Run Code Online (Sandbox Code Playgroud)
negativeButton是一个默认的对话框按钮,采用Android 5 Lollipop的默认绿色.
非常感谢

android textcolor android-layout android-alertdialog android-5.0-lollipop
最近我从支持库切换到com.google.android.material:material:1.0.0
但是现在我有一个问题,在这个页面上有一个注释https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md
注意:使用"材质成分"主题可启用自定义视图填充程序,该填充程序将使用"材质"对应项替换默认组件.目前,这仅使用MaterialButton替换Button XML组件.
我正在使用的主题
Theme.MaterialComponents.Light.NoActionBar
Run Code Online (Sandbox Code Playgroud)
它完全按照它在说明中所说的,它将AlertDialog按钮替换为MaterialButtons,但问题是默认情况下MaterialButtons是彩色背景,现在按钮看起来像这样: 
我怎样才能让它们再次无边界和无背景?
PS我正在使用警报构建器来创建警报对话框:
android.app.AlertDialog.Builder
Run Code Online (Sandbox Code Playgroud) android android-alertdialog android-styles material-design material-components-android
如何使标题、消息和按钮居中对齐
MaterialAlertDialogBuilder(requireContext())
.setTitle("Message")
.setMessage("This is info message.")
.setPositiveButton("Ok") { dialog, which ->
}
.show()
Run Code Online (Sandbox Code Playgroud) java android android-alertdialog kotlin material-components-android
我正在使用MaterialAlertDialogBuilder,因为我想要圆角和白天和夜间模式。请注意,我不能使用dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));线条,因为在我的风格中,我在 style.xml 中有不同的父级,我用它根据日/夜模式设置颜色。
问题:如何更改 MaterialAlertDialogBuilder 中的正/负按钮背景颜色?
请注意,可绘制背景不适用于MaterialAlertDialogBuilder
代码:
public void showNotesDialog() {
MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(this, R.style.dialogBoxStyle);
LayoutInflater li = LayoutInflater.from(this);
View promptsView = li.inflate(R.layout.row_note_layout, null);
alertDialogBuilder.setView(promptsView);
etNote = promptsView.findViewById(R.id.et_note);
String buttonName = getString(R.string.add);
if (!getNotes.isEmpty()) {
buttonName = getString(R.string.update);
etNote.getText().clear();
etNote.setText(getNotes);
}
alertDialogBuilder.setPositiveButton(buttonName, null);
alertDialogBuilder.setNegativeButton(getString(R.string.cancel), null);
alertDialogBuilder.setNeutralButton("Clear", null);
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.setCancelable(false);
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button buttonPositive = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
Button buttonNegative = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE); …Run Code Online (Sandbox Code Playgroud) 这是我创建对话框的代码,
builder.setMessage(msg).setNeutralButton("Dismiss",dialogClickListener)
.setPositiveButton("Edit", dialogClickListener)
.setNegativeButton("Delete", dialogClickListener).show();
Run Code Online (Sandbox Code Playgroud)
是否可以用蓝色而不是红色显示解雇?