Skip to content

TextContrastCheck not handling TextInputLayout.boxStrokeColor correctly #75

@jozuasijsling-ing

Description

@jozuasijsling-ing

A false positive warning by TextContrastCheck is observed when using TextInputLayout from com.google.android.material:material. The check treats box stroke color as a foreground color. By default the box stroke color is transluscent, making it likely to trigger the warning.

Reproduction

Given a blank project from Android Studio's Empty Activity template and the following layout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.textfield.TextInputLayout
        android:padding="24dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Hello World!">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:singleLine="true" />

    </com.google.android.material.textfield.TextInputLayout>

</FrameLayout>

A warning is produced with the following output:

📝 accessibility-test-framework 4.1.1

AccessibilityViewCheckResult check=AccessibilityHierarchyCheckResult WARNING TextContrastCheck 11 [ViewHierarchyElement class=com.google.android.material.textfield.TextInputEditText bounds=Rect(0, 96 - 1080, 423)] {KEY_BACKGROUND_COLOR=-67585, KEY_CONTRAST_RATIO=4.33, KEY_FOREGROUND_COLOR=-8817538, KEY_IS_LARGE_TEXT=false, KEY_REQUIRED_CONTRAST_RATIO=4.5} num_answers:0 view=com.google.android.material.textfield.TextInputEditText{2f293a2 VFED..CL. ........ 0,0-936,167}

📝 Accessibility Scanner 2.4.1.58312255

Accessibility Scanner resultShare text
The following is a list of opportunities to improve the accessibility of My Application. Each item corresponds to an outlined area on the attached screenshot.

Contrast tekst
[72,184][1008,351]
Overweeg de contrastverhouding tussen de voorgrond en achtergrond van deze afbeeldingstekst te verhogen.
De contrastverhouding van de itemtekst is 4,33. Deze verhouding is gebaseerd op de geschatte voorgrondkleur #79747E en de geschatte achtergrondkleur #FEF7FF. Overweeg de contrastverhouding van de itemtekst te verhogen naar 4,50 of hoger.

*For some reason the share text mixes English and Dutch? 🙈 Out of scope.

Negative case

Overriding the default box stroke color with a high contrast color, the warning disappears.

Layout Accessibility Scanner result

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions