【发布时间】:2011-01-22 04:31:45
【问题描述】:
我正在尝试更改 Android 中列表视图的文本颜色。谁能告诉我它是如何完成的?
【问题讨论】:
标签: android android-listview android-text-color
我正在尝试更改 Android 中列表视图的文本颜色。谁能告诉我它是如何完成的?
【问题讨论】:
标签: android android-listview android-text-color
可以
请使用文本视图添加单独的布局
<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>
并更改 **android.R.layout.simple_list_item_1** 像这样传递textview id
新的 ArrayAdapter(这个, R.layout.layoutfilename,*android.R.id.text1*,userList);
【讨论】:
您可以使用主题为您的TextViews 设置样式。
来自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>
然后使用它:
<TextView style="@style/CodeFont" />
编辑 - 基于评论
您询问了同一个 TextView 中的多种颜色: 你最好的选择是使用 html。例如,您在 TextView 中设置的内容:
myTextView.setText(Html.fromHtml("<p style="color:red">" + someText + "</p><p style="color:blue">" + someOtherText + "</p>"));
【讨论】:
您是否在 layout.xml 文件中尝试过类似 android:textColor="#ffffff" 的内容?
【讨论】: