Skip to content

Commit ec8be9a

Browse files
kendrickumstattdpaulfthomas
authored andcommitted
Internal change
PiperOrigin-RevId: 704689311
1 parent 34d5f63 commit ec8be9a

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

lib/java/com/google/android/material/button/MaterialButton.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static java.lang.Math.max;
3030
import static java.lang.Math.min;
3131

32+
import android.annotation.SuppressLint;
3233
import android.content.Context;
3334
import android.content.res.ColorStateList;
3435
import android.content.res.TypedArray;
@@ -322,6 +323,7 @@ private SpringForce createSpringForce() {
322323
}
323324

324325
@NonNull
326+
@SuppressLint("KotlinPropertyAccess")
325327
String getA11yClassName() {
326328
if (!TextUtils.isEmpty(accessibilityClassName)) {
327329
return accessibilityClassName;
@@ -330,7 +332,8 @@ String getA11yClassName() {
330332
return (isCheckable() ? CompoundButton.class : Button.class).getName();
331333
}
332334

333-
void setA11yClassName(@Nullable String className) {
335+
@RestrictTo(LIBRARY_GROUP)
336+
public void setA11yClassName(@Nullable String className) {
334337
accessibilityClassName = className;
335338
}
336339

lib/java/com/google/android/material/button/MaterialSplitButton.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
import static com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap;
2222

2323
import android.content.Context;
24+
import android.os.Build.VERSION;
25+
import android.os.Build.VERSION_CODES;
2426
import android.util.AttributeSet;
2527
import android.view.View;
2628
import android.view.ViewGroup;
29+
import android.widget.Button;
2730
import androidx.annotation.NonNull;
2831
import androidx.annotation.Nullable;
2932

@@ -104,6 +107,25 @@ public void addView(@NonNull View child, int index, @Nullable ViewGroup.LayoutPa
104107
super.addView(child, index, params);
105108
if (indexOfChild(child) == 1) {
106109
buttonChild.setCheckable(true);
110+
buttonChild.setA11yClassName(Button.class.getName());
111+
if (VERSION.SDK_INT >= VERSION_CODES.R) {
112+
// Set initial content description based on checked state when focused.
113+
buttonChild.setStateDescription(
114+
getResources()
115+
.getString(
116+
buttonChild.isChecked()
117+
? R.string.mtrl_button_expanded_content_description
118+
: R.string.mtrl_button_collapsed_content_description));
119+
120+
buttonChild.addOnCheckedChangeListener(
121+
(button, isChecked) ->
122+
button.setStateDescription(
123+
getResources()
124+
.getString(
125+
isChecked
126+
? R.string.mtrl_button_expanded_content_description
127+
: R.string.mtrl_button_collapsed_content_description)));
128+
}
107129
}
108130
}
109131
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2024 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<resources>
19+
<string name="mtrl_button_expanded_content_description" description="An announcement for the expanded menu state of the trailing button in split button [CHAR LIMIT=NONE]">Expanded</string>
20+
<string name="mtrl_button_collapsed_content_description" description="An announcement for the collapsed menu state of the trailing button in split button [CHAR LIMIT=NONE]">Collapsed</string>
21+
</resources>

0 commit comments

Comments
 (0)