Android Accessibility not working in TextInputLayout

Viewed 557

If there is NO Text typed into TextInputEditText, the Android Accessibility talkback will read the hint in TextInputLayout.

However, Android Talkback will NOT read the hint in TextInputLayout if there is text added into the TextInputEditText.

I Need the Accessibility Talkback to Always read the hint in TextInputLayout.

Does anyone know how to do it?

Thanks guys

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:labelFor="@+id/editText"
            android:hint="username">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/editText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

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

The only way you can overwrite that it to:

Extend :

public class CustomTextInputLayoutAccessibilityDelegate extends TextInputLayout.AccessibilityDelegate {...}

Then Overwrite:

public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {

...
// And add the new logic in here:

        if (showingText) {
            if (hasHint) {
                info.setText(String.format("%s, %s", hintText, text));
            } else {
                info.setText(text);
            }
        } else if (hasHint) {
            info.setText(hintText);
        }


}

And set it to your TextInputLayout as:

setTextInputAccessibilityDelegate(new CustomTextInputLayoutAccessibilityDelegate(this));
Related