android - How to modify color attribute in xml during runtime? -
in android game, there textview, background circle gray color. achieving following code in xml.
<textview android:id="@+id/tv0" android:textcolor="#fff" android:textstyle="bold" android:background="@drawable/circle" android:layout_gravity="left" android:gravity="center_vertical|center_horizontal" android:layout_width="50dp" android:layout_height="50dp" />
where circle.xml is
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#aaaaaa" /> <corners android:topleftradius="60dp" android:toprightradius="60dp" android:bottomleftradius="60dp" android:bottomrightradius="60dp" /> </shape>
now want change color of background circle based on user input. possible , how ?
you have background of textview gradientdrawable object , change color:
textview tv = (textview) findviewbyid(r.id.tv0); gradientdrawable gd = (gradientdrawable) tv.getbackground(); gd.setcolor(0xffff99cc);
Comments
Post a Comment