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.
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.
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.
In XML, we can set a text color by the textColor attribute, like android:textColor="#FF0000" .
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
android:background="@android:color/holo_green_light"
seems to work for me. Your target API version does include the Holo theme, right?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With