问题
Here my code for create Dialog,
builder.setMessage(msg).setNeutralButton("Dismiss",dialogClickListener)
.setPositiveButton("Edit", dialogClickListener)
.setNegativeButton("Delete", dialogClickListener).show();
Is it possible to display dismiss in blue color rather than red?
回答1:
First, create AlertDialog from builder:
AlertDialog dialog = builder.create();
Then you can find your button and change color:
dialog.show(); //Only after .show() was called
dialog.getButton(dialog.BUTTON_NEGATIVE).setTextColor(your_color);
dialog.getButton(dialog.BUTTON_POSITIVE).setTextColor(your_color);
dialog.getButton(dialog.BUTTON_NEUTRAL).setTextColor(your_color);
Here you use next method:
void setTextColor (int color)
Sets the text color for all the states (normal, selected, focused) to be this color.
Parameters
color int: A color value in the form 0xAARRGGBB. Do not pass a resource ID. To get a color value from a resource ID, call getColor.
回答2:
Yeah it is possible, change color from style and you can define custom style for your dialog like below:
<style name="AlertDialogCustom" parent="android:Theme.Material.Light.Dialog.Alert">
<item name="android:colorPrimary">yourColorCode</item>
<item name="android:colorAccent">yourColorCode</item>
</style>
来源:https://stackoverflow.com/questions/46397707/how-to-change-color-of-button-in-alert-dialog