I am trying to change the text color of a listview in Android. Can anyone please give me a heads up on how it's done?
Asked
Active
Viewed 4.0k times
3 Answers
22
Yes possible
please add a separate layout with the textview
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingLeft="6dip"
android:textColor="@color/black"
android:paddingRight="10dip"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
and change the **android.R.layout.simple_list_item_1** to and pass the textview id like this
new ArrayAdapter(this, R.layout.layoutfilename,*android.R.id.text1*,userList);

ranjit patel
- 757
- 1
- 9
- 21
-
yes, but didn't you mean **R.layout.layoutfilename, R.id.text1** ? – Mikhail V Jan 28 '15 at 13:42
6
You can use themes to set the styles for your TextViews
.
From the Android dev site.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
</resources>
Then to use it:
<TextView style="@style/CodeFont" />
Edit - based on comment
You asked about multiple color in the same TextView: Your best bet is to use html. Which you set in a TextView for example:
myTextView.setText(Html.fromHtml("<p style="color:red">" + someText + "</p><p style="color:blue">" + someOtherText + "</p>"));

Tristan Warner-Smith
- 9,631
- 6
- 46
- 75
-
1HI, the question asked is How to change the color of text inside the list view. could you please explain how to do that. – DAS Nov 25 '11 at 05:52
-
If you want multiple bits of text of different colours then your best bet is to use html. Which you set in a TextView like this: – Tristan Warner-Smith Nov 28 '11 at 10:32
-
@Tristan.... can we uset font from assest folder using style code.. means we do not have to do run time coding... for typeface... – Jishant Mar 15 '16 at 11:02
-6
Have you tried something like android:textColor="#ffffff"
in your layout.xml file?

Ta Sas
- 9,573
- 15
- 51
- 73