Skip to content

Commit 78bcc15

Browse files
committed
Switch does not append its state text to accessibility node infos.
1. Switch was not populating the state on/off test in accessibility node infos. It apparently has two texts, the state one and the one it inherits from TextView. bug:6213278 Change-Id: I9c6b1798a8b3230cfb6755cc5b088c320d991642
1 parent f21bea2 commit 78bcc15

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

core/java/android/widget/Switch.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,5 +806,16 @@ public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
806806
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
807807
super.onInitializeAccessibilityNodeInfo(info);
808808
info.setClassName(Switch.class.getName());
809+
CharSequence switchText = isChecked() ? mTextOn : mTextOff;
810+
if (!TextUtils.isEmpty(switchText)) {
811+
CharSequence oldText = info.getText();
812+
if (TextUtils.isEmpty(oldText)) {
813+
info.setText(switchText);
814+
} else {
815+
StringBuilder newText = new StringBuilder();
816+
newText.append(oldText).append(' ').append(switchText);
817+
info.setText(newText);
818+
}
819+
}
809820
}
810821
}

0 commit comments

Comments
 (0)