androidandroid-listviewandroid-text-color

Changing text color of list view in android


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?


Solution

  • 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>"));