1

I am trying to change the EditText blinking cursor color in Alert Dialog because it's not what I want. The color is teal, I want white. Nothing I am doing is changing it. Here is what I mean... Alert Dialog With EditText](https://www.bing.com/images/search?view=detailV2&ccid=K1%2fOkkYC&id=7A70653842861A8EF4C2E3FA144B2E06F8A6253E&thid=OIP.K1_OkkYCaIu062eXXFNgjQAAAA&mediaurl=https%3a%2f%2fi.stack.imgur.com%2fKPKvQ.png&exph=193&expw=400&q=edittext+in+alertdialog+colors&simid=608013895961150146&selectedIndex=0)[![enter image description here]1

Here is what I have...

Java Code:

public void alertDialogWithText(){
    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));
    adb.setView(inputET);

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

        }
    });

    adb.show();
}

Colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#303030</color>
<color name="colorPrimaryDark">#000</color>
<color name="colorAccent">#fff</color>
</resources>

Styles.xml:

<style name="EditTextAlertDialog">
    <item name="android:textColor">@android:color/white</item>
    <item name="android:background">#444</item>
</style>
Zoe
  • 27,060
  • 21
  • 118
  • 148
cryptic_coder
  • 181
  • 1
  • 2
  • 10
  • One option is to set the dialog style. In this example, the cursor is green: – Zee May 29 '19 at 11:48
  • Thanks Zee. Unfortunately, your suggestion changes everything but the cursor color. It seems that when an EditText is used in a xml layout colorAccent controls this,but not when the EditText is used in a Alert Dialog. If I use a custom style and I use the attribute android:colorAccent it doesn't change it. I don't think the cursor color can be changed from the default color teal when the EditText is used in an Alert Dialog. So, I reluctantly setCursorVisible to false. I am not happy about it, but I guess it is what it is. – cryptic_coder May 29 '19 at 12:08
  • Wait, did you do this: newFragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomDialog); to apply the style to the dialog? I had the exact same problem and I think I solved it like this (honestly, I cant remember though). Maybe play around with the style, such as setting other attributes, for example @color/buttonColour or @color/colorAccent – Zee May 29 '19 at 12:10
  • No, I used this method... AlertDialog.Builder adb = new AlertDialog.Builder(new ContextThemeWrapper(MainActivity.this, R.style.CustomDialog)); I even tried adding the attribute android:colorAccent and to no avail. – cryptic_coder May 29 '19 at 12:14

0 Answers0