Skip to content

Commit 7f97e54

Browse files
sganovAndroid (Google) Code Review
authored andcommitted
Merge "Switch does not append its state text to accessibility node infos."
2 parents 11e0781 + 78bcc15 commit 7f97e54

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)