I have an EditText like below
<EditText
android:id="@+id/extUsername"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="Username field"
android:hint="Username" />
I want TalkBack to say "Username field" but it says "Username". It ignores contentDescription.
Do not tell me to remove hint or contentDescription. I need to use both.
Any advices will be appreciated.
You need to add it in your string.xml file:
What you want to do is use LabelFor instead. LabelFor allows a visual label to be associated with an EditText box. You can make the visual label invisible if you'd like, so that it doesn't change your visual layout.
The down side to hints, is that they disappear after text is entered, making them pretty poor accessibility tools. If you're relying on hints for your Accessibility information, your app is not accessible.
Do something like this:
Unfortunately, android:hint will always override android:contentDescription. You can create TextView which you will use only to set android:labelFor but from my experience TalkBack will then read both hint and labelFor.
The right way to add TextView which is only for labeling EditText for TalkBack :
So one of the solutions is that you can check to see if TalkBack is on and change hint programmatically. You can check if TalkBack is on with:
And you create an inline function in Kotlin like :
You should extend EditText class with overriden TextView.getTextForAccessibility() method to get expected behaviour in the following way:
According to the official documentation, you shouldn't be setting
android:contentDescription
equal to anything. Instead, only useandroid:hint
."field" from your
contentDescription
should be removed, because TalkBack will announce it as "Username edit box"Note: For EditText fields, provide an android:hint attribute instead of a content description, to help users understand what content is expected when the text field is empty. When the field is filled, TalkBack reads the entered content from content description to help user, instead of the hint text.
For Hint -> android:hint
For TalkBack -> android:contentdescription