Commit fa649038 authored by Wenyu Fu's avatar Wenyu Fu Committed by Commit Bot

Fix talkback read out for RadioButtonWithEditText

In the original implementation, screen reader cannot read out the
content for RadioButtonWithEditText. This change makes the EditText as
the label of the widget, so that the content description for EditText
can be read out as part of the RadioButtonWithEditText.

Before the change, RadioButtonWithEditText read out as
"Checked/Unchecked radio button"; after the change, the widget read out
as "Checked/Unchecked radio button for <read out for EditText>", which
will contains:
1. The Radio button is for a EditText
2. The text & hint for EditText

Bug: 1057269
Change-Id: I23cabe4b7bc8313bbc8c055a95f5a9e26e876b7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2090620
Commit-Queue: Theresa  <twellington@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748471}
parent 10b9f2aa
......@@ -10,6 +10,7 @@ import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.EditText;
import android.widget.TextView;
......@@ -118,6 +119,15 @@ public class RadioButtonWithEditText extends RadioButtonWithDescription {
mEditText.setOnFocusChangeListener((v, hasFocus) -> { onEditTextFocusChanged(hasFocus); });
}
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
// Fix the announcement for a11y as EditText cannot be correctly read out as a child
// of a ViewGroup. Setting EditText as the label for this custom view is a workaround
// as label will be announce at end of ViewGroup's readable a11y children.
super.onInitializeAccessibilityNodeInfo(info);
info.setLabeledBy(mEditText);
}
@Override
protected TextView getPrimaryTextView() {
return findViewById(R.id.edit_text);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment