Skip to content

Instantly share code, notes, and snippets.

@krossovochkin
Created January 18, 2020 12:35
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 krossovochkin/9f1190311910df185a3771540f49a314 to your computer and use it in GitHub Desktop.
Save krossovochkin/9f1190311910df185a3771540f49a314 to your computer and use it in GitHub Desktop.
Theme_1
class MyTextView
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AppCompatTextView(context, attrs, defStyleAttr),
ThemeManager.ThemeChangedListener {
override fun onFinishInflate() {
super.onFinishInflate()
ThemeManager.addListener(this)
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
ThemeManager.addListener(this)
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
ThemeManager.removeListener(this)
}
override fun onThemeChanged(theme: ThemeManager.Theme) {
setTextColor(
ContextCompat.getColor(
context,
theme.textViewTheme.textColor
)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment