Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

ColorBindingType

CraZyLegenD edited this page Aug 26, 2020 · 4 revisions
enum class ColorBindingType {
    TEXT_COLOR, CARD_VIEW_BACKGROUND, IMAGE_TINT
}

Changes the text color of a TextView/AppcompatTextView/MaterialTextView

TEXT_COLOR //responsible for the following
textView.setTextColor(getCompatColor(model.myColorBoundVariable))

Changes the background color of a CardView/MaterialCardView

CARD_VIEW_BACKGROUND //responsible for the following
cardView.setBackgroundColor(getCompatColor(model.myColorBoundVariable))

Changes the tint of an AppCompatImageView, meaning do not use ImageView but use the app compat version

IMAGE_TINT //responsible for the following
ImageViewCompat.setImageTintList(appCompatImageView.ColorStateList.valueOf(model.myColorBoundVariable))

All of these annotations use @ColorRes and are bound to the views using

fun getCompatColor(colorRes: Int): Int = ContextCompat.getColor(context, colorRes)
Clone this wiki locally