Skip to content

Instantly share code, notes, and snippets.

Created August 13, 2021 09:40
What would you like to do?
class SelectableChipView
@JvmOverloads constructor(
context: Context,
attributeSet: AttributeSet? = null,
defStyleAttr: Int = 0
) : AppCompatTextView(context, attributeSet, defStyleAttr) {
init {
clipToOutline = true
outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setRoundRect(0, 0, view.width, view.height, 20f)
// here we are just adding round rect or "chip" shape to our view
fun bind(isSelected: Boolean) {
setBackgroundColor(if (isSelected) Color.BLACK else Color.LTGRAY)
setTextColor(if (isSelected) Color.WHITE else Color.BLACK)
// here we are changing a colors depending on isSelectedFlag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment