On background color change listener - Android

Viewed 153

How can I create a listener for the background color change of my view?

I have this approach and it doesn't work:

init {
    subject.setTag(subject.background);
    subject.getViewTreeObserver().addOnGlobalLayoutListener(ViewTreeObserver.OnGlobalLayoutListener {
        val newVis: Int = (subject.background as ColorDrawable).color
        if ((subject.getTag() as ColorDrawable).color != newVis) {
            subject.setTag(subject.background)
            notifySourceChanged()
        }
    })
}

where subject is my View. Can anyone help me. Thanks!

0 Answers
Related