Here is my code
theme?.let {
....
titleText.setTextColor(it.pTextColor)
contentText.setTextColor(it.pTextColor)
}
}
and the usage of this extension is here
cardView.setTheme(theme)
How can I have this cardView.theme = theme
Here is my code
theme?.let {
....
titleText.setTextColor(it.pTextColor)
contentText.setTextColor(it.pTextColor)
}
}
and the usage of this extension is here
cardView.setTheme(theme)
How can I have this cardView.theme = theme
you can write extension function:
fun CardView.setTheme(theme: Theme) {
val titleText = findViewById<TextView>(R.id.text)
val contentText = findViewById<TextView>(R.id.content)
titleText.setTextColor(theme.pTextColor)
contentText.setTextColor(theme.pTextColor)
}
or extension property:
var CardView.theme: Theme?
get() = null
set(value) {
value ?: return
val titleText = findViewById<TextView>(R.id.text)
val contentText = findViewById<TextView>(R.id.content)
titleText.setTextColor(value.pTextColor)
contentText.setTextColor(value.pTextColor)
}