1

I am trying to customize my Alert Dialog but I can't seem to find a way to change the Divider between the text message and the buttons.

I have this custom Alert Dialog theme in my styles.xml:

<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/maroon</item>
    <item name="colorAccent">@color/primary</item>
</style>

And this is the Alert Dialog in my Activity:

final AlertDialog.Builder alertDialog = new AlertDialog.Builder(ChefMenuActivity.this,R.style.AlertDialogCustom);



                    final EditText edittext = new EditText(getApplicationContext());
                    alertDialog.setMessage("Item name: " + menuList.get(position).getItemName() + "\n" + "Old quantity: " + menuList.get(position).getQty_left());
                    alertDialog.setTitle("Change item quantity");

                    edittext.setTextColor(Color.BLACK);
                    edittext.setHint("E.g.: 10");
                    edittext.setHintTextColor(Color.GRAY);
                    edittext.setInputType(InputType.TYPE_CLASS_NUMBER);

                    alertDialog.setView(edittext);

                    alertDialog.setPositiveButton("REMOVE", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            Toast.makeText(getApplicationContext(), "Not impemented yet", Toast.LENGTH_SHORT).show();
                            dialog.cancel();
                        }
                    });

                    alertDialog.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            Toast.makeText(getApplicationContext(), "Not impemented yet", Toast.LENGTH_SHORT).show();
                            dialog.cancel();
                        }
                    });

                    alertDialog.setNeutralButton("UPDATE", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            Toast.makeText(getApplicationContext(), "Not impemented yet", Toast.LENGTH_SHORT).show();
                            dialog.cancel();
                        }
                    });

                    alertDialog.show();

I found a piece of code to change the divider between the title and the message:

                AlertDialog dialog = alertDialog.show();

                int titleDividerId = getResources().getIdentifier("titleDivider", "id", "android");
                View titleDivider = dialog.findViewById(titleDividerId);
                if (titleDivider != null)
                    titleDivider.setBackgroundColor(Color.parseColor("#ff4444"));

But it is not valid for my case since I want to change the divider between the message and the button (like in the picture below).

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Marcos Guimaraes
  • 1,243
  • 4
  • 27
  • 50

2 Answers2

0

Use this library

https://github.com/danoz73/QustomDialog

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

qustomDialogBuilder.show();

or you can do this

    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));

you can find more answers here

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Manohar
  • 22,116
  • 9
  • 108
  • 144
0

As it was said above, the thing I wanted to change was not the divider but the background of the edit text. I had to use editText.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN); to change edittext underline color.

Marcos Guimaraes
  • 1,243
  • 4
  • 27
  • 50