问题
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.
回答1:
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:
<TextView
android:text="@string/yourEditTextDescription"
android:labelFor="@+id/editTextField" />
<EditText android:id="@+id/editTextField"/>
回答2:
According to the official documentation, you shouldn't be setting android:contentDescription
equal to anything. Instead, only use android:hint
.
<EditText
android:id="@+id/extUsername"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Username" />
"field" from your contentDescription
should be removed, because TalkBack will announce it as "Username edit box"
回答3:
You should extend EditText class with overriden TextView.getTextForAccessibility() method to get expected behaviour in the following way:
public CharSequence getTextForAccessibility() {
CharSequence text = getText();
if (TextUtils.isEmpty(text)) {
text = getContentDescription();
}
return text;
}
回答4:
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
回答5:
You need to add it in your string.xml file:
<string name="description">your desc goes here</string>
来源:https://stackoverflow.com/questions/29889904/android-talkback-hint-overwrites-contentdescription