如何改变简单的列表项的文字颜色 [英] How to change text color of simple list item
问题描述
我有一个ListActivity,我显示一个列表:
I have an ListActivity and i am displaying one list with:
setListAdapter(new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_single_choice, mStringList));
通过列表项默认的文本颜色是白色的,我想改变的文本视图文本颜色列表中为黑色。
By default text color of list items is white, I want to change text color of text views in the list to black.
我应该怎么办呢?
推荐答案
另一种简单的方法是创建一个包含你想与TEXTSIZE,文本样式,由您pferred,然后使用它的颜色等$ P $ TextView的布局文件ArrayAdapter。
Another simplest way is to create a layout file containing the textview you want with textSize, textStyle, color etc preferred by you and then use it with the ArrayAdapter.
例如。 mytextview.xml
e.g. mytextview.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tv"
android:textColor="@color/font_content"
android:padding="5sp"
android:layout_width="fill_parent"
android:background="@drawable/rectgrad"
android:singleLine="true"
android:gravity="center"
android:layout_height="fill_parent"/>
,然后使用它与您ArrayAdapter像往常一样喜欢
and then use it with your ArrayAdapter as usual like
ListView lst = new ListView(context);
String[] arr = {"Item 1","Item 2"};
ArrayAdapter<String> ad = new ArrayAdapter<String>(context,R.layout.mytextview,arr);
lst.setAdapter(ad);
这样你就不需要创建自定义适配器吧。
This way you won't need to create a custom adapter for it.
这篇关于如何改变简单的列表项的文字颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!