changing shape color programmatically in android -


this question has answer here:

i trying change color of shape in programmatically, not working.

here 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 how using background of 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 how changing color

gradientdrawable bgshape = (gradientdrawable)btn_colorpick.getbackground(); bgshape.setcolor(color.red); 

but when ever change background color, removes button screen.

change code below

gradientdrawable bgshape = (gradientdrawable)btn_colorpick.getbackground();  bgshape.mutate()  bgshape.setcolor(color.red); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -