【问题标题】:Changing text color of list view in android在android中更改列表视图的文本颜色
【发布时间】:2011-01-22 04:31:45
【问题描述】:

我正在尝试更改 Android 中列表视图的文本颜色。谁能告诉我它是如何完成的?

【问题讨论】:

    标签: android android-listview android-text-color


    【解决方案1】:

    可以

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

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

    【讨论】:

    • 是的,但您不是说 R.layout.layoutfilename, R.id.text1 吗?
    【解决方案2】:

    您可以使用主题为您的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("&lt;p style="color:red"&gt;" + someText + "&lt;/p&gt;&lt;p style="color:blue"&gt;" + someOtherText + "&lt;/p&gt;"));

    【讨论】:

    • 您好,问题是如何更改列表视图中文本的颜色。你能解释一下怎么做吗?
    • 如果您想要多位不同颜色的文本,那么最好的选择是使用 html。您在这样的 TextView 中设置:
    • @Tristan....我们可以使用样式代码从assest文件夹中使用字体吗..意味着我们不必为字体进行运行时编码...
    【解决方案3】:

    您是否在 layout.xml 文件中尝试过类似 android:textColor="#ffffff" 的内容?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多