0

I have an EditText in an AlertDialog and the bottom line color is not what I want, and I can't figure out how to change it.

Here is what I have so far.

AlertDialog.Builder adb = new AlertDialog.Builder(new ContextThemeWrapper(MainActivity.this, R.style.EditTextAlertDialog));
    adb.setTitle("Title");
    inputET = new EditText(this);
    inputET.setInputType(InputType.TYPE_CLASS_TEXT);
    inputET.setTextColor(getResources().getColor(android.R.color.white));
   inputET.setHighlightColor(getResources().getColor(android.R.color.white)); //This should change it, but it's not.
    adb.setView(inputET);

    adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });

    adb.show();

For some weird reason that is not working, setHightlightColor should be it.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
cryptic_coder
  • 181
  • 1
  • 2
  • 10

4 Answers4

0

You can create a style for your dialog.

<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorAccent">@color/yourEditTextColor</item>
    </style>

And then add it while creating your Dialog

AlertDialog.Builder adb = new AlertDialog.Builder(new ContextThemeWrapper(MainActivity.this, R.style.MyDialogTheme));
Arun
  • 321
  • 2
  • 8
  • I've tried that and that doesn't work. Changing it in the code snippet seems to be the only way it will change. Dinesh's solution worked for me. – cryptic_coder May 28 '19 at 13:17
  • @lllcoderlll Ok. I had used it for a Dialog(not AlertDialog) with a xml layout and it worked well. Guess it doesn't work for a AlertDialog. – Arun May 28 '19 at 14:57
0

You need to set the Background Tint for that use :

inputET.setBackgroundTintList(ColorStateList.valueOf(intColorCode));
Mitesh Machhoya
  • 404
  • 2
  • 8
0

Under the xml file put it this way into ur EditText: app:backgroundTint="@color/black"

Catluc
  • 1,775
  • 17
  • 25
0

You can do something different.

Define a layout with an TextInputLayout using a Filled Box Theme(Default) applying the app:boxStrokeColor attribute to change the color of underline.

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="?attr/dialogPreferredPadding"
    android:paddingStart="?attr/dialogPreferredPadding"
    android:paddingEnd="?attr/dialogPreferredPadding">

  <com.google.android.material.textfield.TextInputLayout
      android:id="@+id/text_input_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_margin="4dp"
      app:boxStrokeColor="@color/my_favorite_color"
      android:hint="Hint text">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
  </com.google.android.material.textfield.TextInputLayout>
</FrameLayout>

Then just build the AlertDialog with the defined layout:

new MaterialAlertDialogBuilder(AlertDialogActivity.this)
            .setTitle("Dialog")
            .setMessage("Lorem ipsum dolor ....")
            .setView(R.layout.custom_text_alert_dialog)
            .setPositiveButton("Ok", /* listener = */ null)
            .setNegativeButton("Cancel", /* listener = */ null)
            .show();

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841