Skip to content Skip to sidebar Skip to footer

How To Change Alert Dialog Header Divider Color Android

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

Solution 1:

You can actually change color of AlertDialog title by a very simple hack:

publicstaticvoidbrandAlertDialog(AlertDialog dialog) {
    try {
        Resourcesresources= dialog.getContext().getResources();
        intcolor= resources.getColor(...); // your color hereintalertTitleId= resources.getIdentifier("alertTitle", "id", "android");
        TextViewalertTitle= (TextView) dialog.getWindow().getDecorView().findViewById(alertTitleId);
        alertTitle.setTextColor(color); // change title text colorinttitleDividerId= resources.getIdentifier("titleDivider", "id", "android");
        ViewtitleDivider= dialog.getWindow().getDecorView().findViewById(titleDividerId);
        titleDivider.setBackgroundColor(color); // change divider color
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

Solution 2:

Divider color:-

AlertDialog.Builderbuilder=newAlertDialog.Builder(getActivity());
builder.setTitle(R.string.dialog)
   .setIcon(R.drawable.ic)
   .setMessage(R.string.dialog_msg);
Dialogd= builder.show();
intdividerId= d.getContext().getResources().getIdentifier("android:id/titleDivider", null, null);
Viewdivider= d.findViewById(dividerId);
divider.setBackgroundColor(getResources().getColor(R.color.my_color));

Solution 3:

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.

Solution 4:

QustomDialogBuilderqustomDialogBuilder=newQustomDialogBuilder(context).
        setTitle("Set IP Address").
        setTitleColor("#FF00FF").
        setDividerColor("#FF00FF").
        setMessage("You are now entering the 10th dimension.").
qustomDialogBuilder.show();

Post a Comment for "How To Change Alert Dialog Header Divider Color Android"