Skip to content

Commit 7ae12b5

Browse files
pekingmeleticiarossi
authored andcommitted
[ButtonGroup] Updated to only draw surface color under the button's stroke when the buttons are actually overlapped.
PiperOrigin-RevId: 753629476
1 parent 30f1850 commit 7ae12b5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public void onViewRemoved(View child) {
245245
adjustChildMarginsAndUpdateLayout();
246246
}
247247

248-
private void recoverAllChildrenLayoutParams(){
248+
private void recoverAllChildrenLayoutParams() {
249249
for (int i = 0; i < getChildCount(); i++) {
250250
MaterialButton child = getChildButton(i);
251251
child.recoverOriginalLayoutParams();
@@ -408,6 +408,14 @@ private void adjustChildMarginsAndUpdateLayout() {
408408
int smallestStrokeWidth = 0;
409409
if (spacing <= 0) {
410410
smallestStrokeWidth = min(currentButton.getStrokeWidth(), previousButton.getStrokeWidth());
411+
// Enables the flag to draw additional layer of surface color under the stroke, which may
412+
// overlap with its neighbors and results unintended color when the stroke color is
413+
// semi-transparent.
414+
currentButton.setShouldDrawSurfaceColorStroke(true);
415+
previousButton.setShouldDrawSurfaceColorStroke(true);
416+
} else {
417+
currentButton.setShouldDrawSurfaceColorStroke(false);
418+
previousButton.setShouldDrawSurfaceColorStroke(false);
411419
}
412420

413421
LayoutParams params = buildLayoutParams(currentButton);

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

-3
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,6 @@ private void setupButtonChild(@NonNull MaterialButton buttonChild) {
522522
buttonChild.setEllipsize(TruncateAt.END);
523523
buttonChild.setCheckable(true);
524524
buttonChild.setA11yClassName(getChildrenA11yClassName());
525-
526-
// Enables surface layer drawing for semi-opaque strokes
527-
buttonChild.setShouldDrawSurfaceColorStroke(true);
528525
}
529526

530527
void onButtonCheckedStateChanged(@NonNull MaterialButton button, boolean isChecked) {

0 commit comments

Comments
 (0)