changing shape color programmatically in android -
this question has answer here:
- how change shape color dynamically? 11 answers
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
Post a Comment