Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a textview's background color to be holo green light via XML?

Tags:

I've got a textview and I'd let to set its background color to be holo green light as mentioned here.

However, I can't figure out how to do this via XML. Is it possible? I currently have:

    <TextView         android:text="2"         android:textSize="200sp"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:id="@+id/textView2"         android:background="#00FF00"         android:gravity="center"         android:textColor="#EEEEEE"         android:layout_alignParentRight="true" /> 

However, I'm unable to change android:background to somehow reference holo green light.

Does anyone have any suggestions? I've tried "@android:color/" but no dice.

like image 680
Gabe Avatar asked Jul 03 '12 22:07

Gabe


People also ask

How do I change text color in XML?

Android TextView – Text Color. 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 add color to TextView?

There are two methods of changing the color of a TextView and the code for that has been given in both Java and Kotlin Programming Language for Android, so it can be done by directly adding a color attribute in the XML code or we can change it through the MainActivity File.

What attribute changes the color of TextView?

In XML, we can set a text color by the textColor attribute, like android:textColor="#FF0000" .


2 Answers

Via Java:

TextView test = (TextView) view.findViewById(R.id.textView2); test.setBackgroundResource(context.getResources().getColor(android.R.color.holo_green_light)); 

Via XML:

 <TextView         android:text="2"         android:textSize="200sp"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:id="@+id/textView2"         android:style="@style/textviewStyle"          android:background="@android:color/holo_green_light"         android:gravity="center"         android:textColor="#EEEEEE"         android:layout_alignParentRight="true" /> 

This is the API page about this topic

like image 148
Alex W Avatar answered Sep 22 '22 07:09

Alex W


android:background="@android:color/holo_green_light" seems to work for me. Your target API version does include the Holo theme, right?

like image 27
Bryan Herbst Avatar answered Sep 21 '22 07:09

Bryan Herbst