我有一个 ListActivity,我正在显示一个列表:
setListAdapter(new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_single_choice, mStringList));
默认情况下,列表项的文本颜色为白色,我想将列表中文本视图的文本颜色更改为黑色。
我该怎么做呢?
另一种最简单的方法是创建一个布局文件,其中包含您想要的文本视图以及您喜欢的文本大小、文本样式、颜色等,然后将其与 ArrayAdapter 一起使用。
例如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 一起使用
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);
这样您就不需要为其创建自定义适配器。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)