How to set chip selected color? (single selection)
On https://material.io/develop/android/components/chip/, there is only app:chipBackgroundColor, which is when is the color even when it is not selected.
I answered on StackOverflow, but I will repeat it here just in case.
Set an attribute app:chipBackgroundColor and pass a color state list to it:
<android.support.design.chip.Chip
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkable="true"
android:clickable="true"
android:focusable="true"
app:chipBackgroundColor="@color/bg_chip_state_list"
app:chipText="Test" />
bg_chip_state_list looks like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorSecondaryLight" android:state_checked="true" />
<item android:color="@color/colorPrimaryDark" />
</selector>
However I also had to set android:clickable to true to make this work
Cool, it's working. Thanks.
https://developer.android.com/guide/topics/resources/color-list-resource
Now almost the same question, how to do the same with text color?
@jeffreyliu8
in Chip's xml:
android:textAppearance="@style/ChipUncheckedText"
and then in styles.xml
<style name="ChipUncheckedText" parent="TextAppearance.MaterialComponents.Chip"">
<item name="android:textColor">@color/colorWhite</item>
</style>
also, regarding the original question, I also had to set android:checkable="true" to make the color state list work.
where do i make the file bg color state list file?
@pranjal012 You can check the official docs about color state list resources: https://developer.android.com/guide/topics/resources/color-list-resource
Most helpful comment
I answered on StackOverflow, but I will repeat it here just in case.
Set an attribute
app:chipBackgroundColorand pass a color state list to it:bg_chip_state_list looks like this:
However I also had to set
android:clickabletotrueto make this work