-
-
Save andreymusth/0cf5175461d86f1e1ec6e138e4fc2519 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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