skip to Main Content

I got a "Insufficient text color contrast ratio" warning in my layout. When I used the "Fix" option in the warning screen, it added an attribute android:hintTextColor to my text view in the xml file.

When I built the project, I got an error saying that the above attribute was not found. When I searched through all the attributes for the TextView, the most similar attribute I could find is textColorHint.

Is this a bug in Android Studio? Or did I get something wrong?

Thanks

3

Answers


  1. This warning does not require any Attribute to be added, all you need to do is to enhance the contrast between the text and the background.

    e.g. Set font to white if your background is black

    If there is no improvement, you can try to use less complicated patterns as background.

    Login or Signup to reply.
  2. Use android:background="@color/white" and android:textColorHint="@color/white" in TextInputEditText and the warning will be gone. see below how I used it.

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/dru_input_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Type Something"
        android:textColorHint="@color/black">
    
        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/dru_edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColorHint="@color/black"
            android:background="@color/white"/>
    </com.google.android.material.textfield.TextInputLayout>
    

    Edit: As the above code will hide InputLayout border to avoid that set you parent view color to white see the below code.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        xmlns:app="http://schemas.android.com/apk/res-auto">
    
        <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/dru_input_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Type Something"
        android:textColorHint="@color/black">
    
        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/dru_edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColorHint="@color/black"/>
    </com.google.android.material.textfield.TextInputLayout>
    </LinearLayout>
    
    Login or Signup to reply.
  3. You just go to this type of side website for a color contrast ratio calculator. Like
    https://coolors.co/contrast-checker/ffffff-006fe6

    Stem1 Now, input your text color and background color. Then Click on to Enhance Buttonenter image description here. You can adjust the text color, background color, or both colors. Maybe it will help you. Thanks

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search