Skip to content

Instantly share code, notes, and snippets.

@andreymusth
Created August 13, 2021 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreymusth/0cf5175461d86f1e1ec6e138e4fc2519 to your computer and use it in GitHub Desktop.
Save andreymusth/0cf5175461d86f1e1ec6e138e4fc2519 to your computer and use it in GitHub Desktop.
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