I wanted to style or change divider color of header title in alert dialog. I search about this question and I think lot of people searching for this.But I am still not able to find out right solution. I want to change this following.

- 11,461
- 20
- 72
- 111

- 7,408
- 32
- 99
- 176
-
have you tried setDivider method? does it exist in alert dialogs? – Paschalis Mar 07 '13 at 12:45
-
I created costume dialog for my older android versions but for newer android version i want to change this blue divider color. for older version i fully create my custom dialog. But i don't want to use it for higher versions. So that's problem. Any way to change that. – nilkash Mar 07 '13 at 12:51
-
if so ,you don't want to create custom dialog then you may have to change the theme , or else you have to use custom dialog box.. – Janmejoy Mar 07 '13 at 12:54
-
I tired it into them as well see I change color of header title. But I am not able to change that divider color. And I really don't want to use custom alert dialog for my higher version of android. – nilkash Mar 07 '13 at 12:57
-
did you find solution? – Mario Zderic Apr 11 '13 at 10:03
-
1This may help you:- http://stackoverflow.com/questions/14439538/how-can-i-change-the-color-of-alertdialog-title-and-the-color-of-the-line-under – pRaNaY Jun 11 '15 at 09:31
5 Answers
You can actually change color of AlertDialog title by a very simple hack:
public static void brandAlertDialog(AlertDialog dialog) {
try {
Resources resources = dialog.getContext().getResources();
int color = resources.getColor(...); // your color here
int alertTitleId = resources.getIdentifier("alertTitle", "id", "android");
TextView alertTitle = (TextView) dialog.getWindow().getDecorView().findViewById(alertTitleId);
alertTitle.setTextColor(color); // change title text color
int titleDividerId = resources.getIdentifier("titleDivider", "id", "android");
View titleDivider = dialog.getWindow().getDecorView().findViewById(titleDividerId);
titleDivider.setBackgroundColor(color); // change divider color
} catch (Exception ex) {
ex.printStackTrace();
}
}

- 1,432
- 15
- 20
-
2
-
-
@Patrick can you please mention on which Android versions it doesn't work, e.g. below 15 on 17+ etc, so it will help others by no need to check for different versions – Shirish Herwade Mar 15 '16 at 11:36
Divider color:-
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.dialog)
.setIcon(R.drawable.ic)
.setMessage(R.string.dialog_msg);
Dialog d = builder.show();
int dividerId = d.getContext().getResources().getIdentifier("android:id/titleDivider", null, null);
View divider = d.findViewById(dividerId);
divider.setBackgroundColor(getResources().getColor(R.color.my_color));

- 24,642
- 24
- 96
- 146
-
1The key here is to run `.show()` first, and then access the dialog to get the divider View and make updates, etc. I missed this at first - was trying to do the color update it before showing the dialog, and wasn't working. Nice concise example - thanks – Gene Bo Dec 12 '17 at 21:04
I have found the easiest solution for updating colors to the alertBuilder's dialog divider.
There is no direct approach to achieve changing the color of the alert dialog divider. So, we can bypass the objects of the alert dialog using the ID of the default divider.
Usually, we will add alert.show() at end of the alertbuilders properties and function. Instead of alert.show() you need to replace the below set of lines to update the divider color for alert dialog.
AlertDialog.Builder alert = new AlertDialog.Builder(SettingActivity.this);
alert.setTitle("Delete");
alert.setMessage("Are you sure want to delete ");
alert.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Delete operations
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
alert.setIcon(android.R.drawable.ic_dialog_alert);
Dialog d = alert.show();
int dividerId = d.getContext().getResources().getIdentifier("android:id/titleDivider", null, null);
View divider = d.findViewById(dividerId);
divider.setBackgroundColor(getResources().getColor(R.color.blue_color));
}
});
Important: You should not use any other alert.show() at the bottom of the code. The alert will automatically take the show properties from the second line as mentioned above.

- 607
- 6
- 26
Judging by the source, it seems that this color is hardcoded. I would consider this a bug, it should be styleable imho.
There is an easy workaround though : use setStyle(DialogFragment.STYLE_NO_TITLE, R.style.myStyle);
, and write a simple linear layout where the first item is your title.

- 4,369
- 4
- 26
- 45
-
2what are you applying setStyle to? There is no such method for AlertDialogs (that I can see). If this works I'd be happy to upvote your answer. – PeteH Sep 13 '13 at 08:24
-
1I use it in the onCreate of DialogFragment (and I advise you to use dialog fragments instead of fragments : http://stackoverflow.com/questions/13765127/dialogfragment-advantages-over-alertdialog ) – Teovald Sep 14 '13 at 20:00
QustomDialogBuilder qustomDialogBuilder = new QustomDialogBuilder(context).
setTitle("Set IP Address").
setTitleColor("#FF00FF").
setDividerColor("#FF00FF").
setMessage("You are now entering the 10th dimension.").
qustomDialogBuilder.show();

- 37
- 7