Set com.google.android.material.chip.Chip selected color

后端 未结 6 1392
你的背包
你的背包 2021-02-01 02:42

How do I set the selected com.google.android.material.chip.Chip color? I don\'t want it to be the default gray. This is a single selection chip group.

Original

6条回答
  •  面向向阳花
    2021-02-01 03:11

    Somehow changing android:textColor in styles doesn't work for me. I have to change the chip's text color programmatically (as I also create chips programmatically).

    val chip = Chip(context)
    // Apply custom MyChipChoice style to the chip
    val drawable = ChipDrawable.createFromAttributes(context!!, null, 0, R.style.MyChipChoice)
    chip.setChipDrawable(drawable)
    // Apply text color to the chip
    val colorStateList = ContextCompat.getColorStateList(context!!, R.color.my_choice_chip_text_color)
    chip.setTextColor(colorStateList)
    

提交回复
热议问题