From 6a55e06d96b5d7d6bd46a36f73a76dcbeef46aaf Mon Sep 17 00:00:00 2001 From: yingleiw Date: Mon, 16 Dec 2019 15:11:26 -0800 Subject: [PATCH] Fix setting state description of toggle button and switch We should set the state description whenever textOn and textOff are updated. Setting it multiple times doesn't hurt because the setStateDescription method won't do anything if the state description is the same. Test: tested with talkback test app. Without the change, a toggle button with textOn and textOff set won't have them announced as the state before a click happens. After the change, a toggle button with textOn and textOff set has them announced as state. Change-Id: Ia1cc6218c8cd0125c123c9b650bb4963825db23a --- core/java/android/widget/Switch.java | 3 +++ core/java/android/widget/ToggleButton.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/core/java/android/widget/Switch.java b/core/java/android/widget/Switch.java index ac2336c4a10f5..fbd29ba2f5927 100644 --- a/core/java/android/widget/Switch.java +++ b/core/java/android/widget/Switch.java @@ -309,6 +309,9 @@ public class Switch extends CompoundButton { // Refresh display with current params refreshDrawableState(); + // Default state is derived from on/off-text, so state has to be updated when on/off-text + // are updated. + setDefaultStateDescritption(); setChecked(isChecked()); } diff --git a/core/java/android/widget/ToggleButton.java b/core/java/android/widget/ToggleButton.java index d47405b3b11ec..59e0c16cde373 100644 --- a/core/java/android/widget/ToggleButton.java +++ b/core/java/android/widget/ToggleButton.java @@ -58,6 +58,9 @@ public class ToggleButton extends CompoundButton { mTextOff = a.getText(com.android.internal.R.styleable.ToggleButton_textOff); mDisabledAlpha = a.getFloat(com.android.internal.R.styleable.ToggleButton_disabledAlpha, 0.5f); syncTextState(); + // Default state is derived from on/off-text, so state has to be updated when on/off-text + // are updated. + setDefaultStateDescritption(); a.recycle(); }