Reputation: 249
I want to get Int
value of background's color of a button.
I try in this way
originalColorOfButton = (button.background.mutate() as ColorDrawable).color
but I get an exception of Java RunTime:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.LoginActivity}: java.lang.ClassCastException: android.graphics.drawable.RippleDrawable cannot be cast to android.graphics.drawable.ColorDrawable
How can I get that?
Upvotes: 0
Views: 70
Reputation: 109
Java:
int backgroundColor = ((ColorDrawable)view.getBackground()).getColor();
Kotlin:
val backgroundColor = (view.background as ColorDrawable).color
Upvotes: 1