24

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.

1
  • The textview background color is displaying for whole screen .Could you please tell me how to set background color for only one line of the textview. For example (Today )is a textview i want green color background for only the textview (TOday). Dec 5, 2013 at 7:33

3 Answers 3

51

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

7

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

1

adding a new info as well it may help someone , u can do this via java as well

        textView.setBackgroundResource(R.color.the_color_you_defind_in_your_colors_._xml);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.