diff --git a/lib/java/com/google/android/material/button/MaterialButtonToggleGroup.java b/lib/java/com/google/android/material/button/MaterialButtonToggleGroup.java index cd6247b0e35..01bed00e65f 100644 --- a/lib/java/com/google/android/material/button/MaterialButtonToggleGroup.java +++ b/lib/java/com/google/android/material/button/MaterialButtonToggleGroup.java @@ -387,13 +387,17 @@ public void setSingleSelection(boolean singleSelection) { } private void updateChildrenA11yClassName() { + String className = getChildrenA11yClassName(); for (int i = 0; i < getChildCount(); i++) { - String className = - singleSelection ? RadioButton.class.getName() : ToggleButton.class.getName(); getChildButton(i).setA11yClassName(className); } } + @NonNull + private String getChildrenA11yClassName() { + return singleSelection ? RadioButton.class.getName() : ToggleButton.class.getName(); + } + /** * Sets whether we prevent all child buttons from being deselected. * @@ -517,6 +521,7 @@ private void setupButtonChild(@NonNull MaterialButton buttonChild) { buttonChild.setMaxLines(1); buttonChild.setEllipsize(TruncateAt.END); buttonChild.setCheckable(true); + buttonChild.setA11yClassName(getChildrenA11yClassName()); // Enables surface layer drawing for semi-opaque strokes buttonChild.setShouldDrawSurfaceColorStroke(true);