繁体   English   中英

在android中更改列表视图的文本颜色

[英]Changing text color of list view in android

我正在尝试更改 Android 中列表视图的文本颜色。 任何人都可以请告诉我它是如何完成的吗?

是的可能

请使用文本视图添加单独的布局

    <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

new ArrayAdapter(this, R.layout.layoutfilename ,* android.R.id.text1 *,userList);

您可以使用主题来设置TextViews的样式。 来自Android 开发网站

<?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"的东西?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM