Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 out right solution. I want to change this following. Blue header divider

like image 204
nilkash Avatar asked Mar 07 '13 12:03

nilkash


2 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();
    }
}
like image 88
MatrixDev Avatar answered Nov 15 '22 00:11

MatrixDev


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));
like image 4
pRaNaY Avatar answered Nov 14 '22 22:11

pRaNaY