I have a <Button/>
<Button
android:id="@+id/btn"
android:background="@drawable/btn_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Button background is set as android:background="@drawable/btn_color"
where btn_color
is
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:padding="10dp">
<solid android:color="#FF0000"/>
<corners android:radius="10dp"/>
</shape>
I need to get the color #FF0000
of the button in my code. What I have tried is
val drawable = btn.getBackground().mutate() as GradientDrawable
How to get the color from this Drawable?