Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply ARGB color to a textview programmatically

I'm currently using something like: TextView.SetBackgroundColor(Color.WHITE); in my java code. I'd like to be able to add some transparancy to the textview through the java... This is easy to do in the XML via #AARRGGBB format, but I have not found a way to accomplish this programmatically.

like image 268
dfetter88 Avatar asked Jul 16 '10 02:07

dfetter88


People also ask

How do I set color programmatically in Kotlin?

TextView Text Color – To change the color of text in TextView, you can set the color in layout XML file using textColor attribute or change the color dynamically in Kotlin file using setTextColor() method.

How do I change the color of an image in programmatically?

Tint color means when we want to change the color of the image while rendering in ImageView. In XML is very easy to change tint color by just setting up the attribute android:tint="" in the ImageView tag, as shown in the following example.

How do I change the background color in TextView?

To change the background color of TextView widget, set the background attribute with required Color value. You can specify color in rgb , argb , rrggbb , or aarrggbb formats. The background color is applied along the width and height of the TextView.


2 Answers

You can use

TextView.SetBackgroundColor(Color.parseColor("#AARRGGBB"));
like image 39
Avijit Avatar answered Oct 06 '22 00:10

Avijit


TextView.SetBackgroundColor(Color.argb(a_int, r_int, g_int, b_int));

Or:

TextView.SetBackgroundColor(Color.parseColor("#AARRGGBB"));
like image 61
eldarerathis Avatar answered Oct 06 '22 01:10

eldarerathis