Skip to content

Commit f1255d9

Browse files
wcshildjcmu
authored andcommitted
Update choice chip to align with spec and use primary color to denote selection.
PiperOrigin-RevId: 246504982
1 parent 2bb0fa1 commit f1255d9

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2019 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+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
19+
<!-- 24% opacity -->
20+
<item android:alpha="0.24" android:color="?attr/colorPrimary" android:state_enabled="true" android:state_selected="true"/>
21+
<item android:alpha="0.24" android:color="?attr/colorPrimary" android:state_enabled="true" android:state_checked="true"/>
22+
<!-- 12% of 87% opacity -->
23+
<item android:alpha="0.10" android:color="?attr/colorOnSurface" android:state_enabled="true"/>
24+
<item android:alpha="0.12" android:color="?attr/colorOnSurface"/>
25+
26+
</selector>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2019 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+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
19+
20+
<item android:alpha="0.16" android:color="?attr/colorPrimary" android:state_pressed="true"/>
21+
<item android:alpha="0.16" android:color="?attr/colorOnSurface" android:state_focused="true" android:state_hovered="true"/>
22+
<item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_focused="true"/>
23+
<item android:alpha="0.04" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
24+
<item android:alpha="0.00" android:color="?attr/colorOnSurface"/>
25+
26+
</selector>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2019 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+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
19+
20+
<item android:color="?attr/colorPrimary" android:state_enabled="true" android:state_selected="true"/>
21+
<item android:color="?attr/colorPrimary" android:state_enabled="true" android:state_checked="true"/>
22+
<!-- 87% opacity. -->
23+
<item android:alpha="0.87" android:color="?attr/colorOnSurface" android:state_enabled="true"/>
24+
<!-- 38% of 87% opacity. -->
25+
<item android:alpha="0.33" android:color="?attr/colorOnSurface"/>
26+
27+
</selector>

lib/java/com/google/android/material/chip/res/values/styles.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@
120120
<item name="closeIconVisible">false</item>
121121

122122
<item name="checkedIcon">@drawable/ic_mtrl_chip_checked_black</item>
123+
124+
<item name="android:textColor">@color/mtrl_choice_chip_text_color</item>
125+
126+
<item name="chipBackgroundColor">@color/mtrl_choice_chip_background_color</item>
127+
<item name="rippleColor">@color/mtrl_choice_chip_ripple_color</item>
128+
123129
</style>
124130

125131
<!-- Style for Chips that act as a button.

0 commit comments

Comments
 (0)