Search code examples
androidxmlandroid-layoutandroid-edittext

How do i change the color for user input in xml?


THIS IS THE OUTPUT

Whenever I type text in the username field, it appears to be black so you can't see what is being typed because of background and input color is the same. I want it to be white or some other color but not black.

I'm not sure why it's happening because I didn't make any changes to style.xml and in MainActivity.xml I did not set the text color black here are files

<EditText android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="45sp"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="293dp"
        android:layout_marginEnd="87sp"
        android:autofill Hints=""
        android:background="#11000000"
        android:drawableStart="@drawable/ic_action_user"
        android:ems="10"
        android:hint="@string/username"
        android:inputType="textPersonName"
        android:textColorLink="#808080"
        android:textColorHint="#808080"/>

My color xml file.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#008577</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B60</color>
</resources>

My style xml file.

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>




Solution

  • In your EditText add textColor like this:

    <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="45sp"
            android:layout_alignParentTop="true"
            android:layout_alignParentEnd="true"
            android:layout_marginTop="293dp"
            android:layout_marginEnd="87sp"
            android:textColor="#FFFFFF"
            android:autofill Hints=""
            android:background="#11000000"
            android:drawableStart="@drawable/ic_action_user"
            android:ems="10"
            android:hint="@string/username"
            android:inputType="textPersonName"
            android:textColorLink="#808080"
            android:textColorHint="#808080"/>
    

    I have changed your EditText text color to white you can change to any other if you like by changing hex code.