Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Dynamically Change TextView Background color

I have following textview in my Activity. I want to change the background color of the textview dynamically.

My problem is I don't want to get the colors from Resouce file or other colors.RED method. I'm getting colors from webservie in websafe mode (i.e #FFF, #000 etc).

How can I pass these colors as background to TextView. Thanks in advance for your time.

<TextView
                android:id="@+id/colorCode"
                android:layout_width="40dp"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true" android:background="#FF0000" android:layout_marginRight="5dp"/>
like image 415
Jay Mayu Avatar asked Nov 11 '11 06:11

Jay Mayu


1 Answers

Below is snippet might help you where txtChannelName is an object of TextView

 txtChannelName.setBackgroundColor(Color.RED);

or

txtChannelName.setBackgroundColor(Color.parseColor("#ffffff"));
like image 89
ingsaurabh Avatar answered Nov 03 '22 10:11

ingsaurabh