-1

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?

nivesh shastri
  • 430
  • 2
  • 13
alberto
  • 115
  • 4
  • 19
  • try this https://stackoverflow.com/questions/39930505/change-color-of-button-in-alertdialog-builder – Vinayak B Sep 25 '17 at 04:42
  • The answer given below by Sheikh teach me about AlertDialog dialog = builder.create(); The answer by Brahmy adigopula in original question just refers to AlertDialog.show out of the blue – alberto Sep 28 '17 at 03:03

2 Answers2

4

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.
Sheikh
  • 1,116
  • 6
  • 15
0

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>
nivesh shastri
  • 430
  • 2
  • 13