Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the background color of a TextView?

How do I get the background color of a TextView?

When I press the TextView, I want to change the background color according to the background color that is in use.

TextView does not have a method such as:

getBackgroundResource()

Edit: I would prefer to get the resId of the background color.

like image 821
OrSmolnik Avatar asked Jun 20 '13 21:06

OrSmolnik


Video Answer


1 Answers

In Kotlin:

    val cd = view.background as ColorDrawable
    val colorCode = cd.color
like image 155
Blücher Avatar answered Oct 02 '22 20:10

Blücher