@@ -167,9 +167,12 @@ public class ChipDrawable extends MaterialShapeDrawable
167167 private static final int [][] states =
168168 new int [][] {
169169 new int [] {
170- android .R .attr .state_enabled , android .R .attr .state_selected
171- }, // enabled and selected
172- new int [] {android .R .attr .state_enabled }, // enabled
170+ android .R .attr .state_enabled , android .R .attr .state_selected ,
171+ },
172+ new int [] {
173+ android .R .attr .state_enabled , android .R .attr .state_checked ,
174+ },
175+ new int [] {android .R .attr .state_enabled },
173176 new int [] {} // default
174177 };
175178
@@ -1288,8 +1291,10 @@ private void updateCompatRippleColor() {
12881291 private void setChipSurfaceColor (@ Nullable ColorStateList chipSurfaceColor ) {
12891292 if (this .chipSurfaceColor != chipSurfaceColor ) {
12901293 this .chipSurfaceColor = chipSurfaceColor ;
1291- if (chipSurfaceColor != null && chipBackgroundColor != null ) {
1292- setFillColor (compositeSurfaceBackgroundColor ());
1294+ if (isShapeThemingEnabled ) {
1295+ if (chipSurfaceColor != null && chipBackgroundColor != null ) {
1296+ setFillColor (compositeSurfaceBackgroundColor (chipBackgroundColor , chipSurfaceColor ));
1297+ }
12931298 }
12941299 onStateChange (getState ());
12951300 }
@@ -1350,30 +1355,21 @@ public void setChipBackgroundColor(@Nullable ColorStateList chipBackgroundColor)
13501355 this .chipBackgroundColor = chipBackgroundColor ;
13511356 if (isShapeThemingEnabled ) {
13521357 if (chipSurfaceColor != null && chipBackgroundColor != null ) {
1353- setFillColor (compositeSurfaceBackgroundColor ());
1358+ setFillColor (compositeSurfaceBackgroundColor (chipBackgroundColor , chipSurfaceColor ));
13541359 }
13551360 }
13561361 onStateChange (getState ());
13571362 }
13581363 }
13591364
1360- private ColorStateList compositeSurfaceBackgroundColor () {
1361- if (chipSurfaceColor == null || chipBackgroundColor == null ) {
1362- return null ;
1365+ private ColorStateList compositeSurfaceBackgroundColor (
1366+ @ NonNull ColorStateList backgroundColor , @ NonNull ColorStateList surfaceColor ) {
1367+ int [] colors = new int [states .length ];
1368+ for (int i = 0 ; i < states .length ; i ++) {
1369+ colors [i ] = MaterialColors .layer (
1370+ surfaceColor .getColorForState (states [i ], currentChipSurfaceColor ),
1371+ backgroundColor .getColorForState (states [i ], currentChipBackgroundColor ));
13631372 }
1364- int [] colors =
1365- new int [] {
1366- MaterialColors .layer (
1367- chipSurfaceColor .getColorForState (states [0 ], currentChipSurfaceColor ),
1368- chipBackgroundColor .getColorForState (states [0 ], currentChipBackgroundColor )),
1369- MaterialColors .layer (
1370- chipSurfaceColor .getColorForState (states [1 ], currentChipSurfaceColor ),
1371- chipBackgroundColor .getColorForState (states [1 ], currentChipBackgroundColor )),
1372- MaterialColors .layer (
1373- chipSurfaceColor .getColorForState (states [2 ], currentChipSurfaceColor ),
1374- chipBackgroundColor .getColorForState (states [2 ], currentChipBackgroundColor )),
1375- };
1376-
13771373 return new ColorStateList (states , colors );
13781374 }
13791375
0 commit comments