Issue
I am trying to change color of a shape in programmatically, but its not working.
Here is the shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#9F2200"/>
<stroke android:width="2dp" android:color="#fff" />
</shape>
here is how i am using it as background of a button
<Button
android:id="@+id/ibtn_EA_ColorPick_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/round_button"
/>
and here is how i am changing its color
GradientDrawable bgShape = (GradientDrawable)btn_ColorPick.getBackground();
bgShape.setColor(Color.RED);
But when ever I change the background color, it removes button from screen.
Solution
Change the code as below
GradientDrawable bgShape = (GradientDrawable)btn_ColorPick.getBackground();
bgShape.mutate()
bgShape.setColor(Color.RED);
Answered By - Manish
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.