【问题标题】:Change Listview item item textcolor更改 Listview 项目项目文本颜色
【发布时间】:2012-07-01 17:01:28
【问题描述】:

您好,我正在使用动态添加多个项目的列表视图。 我想改变 listitem 的文本颜色任何想法

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
       android:layout_height="wrap_content"
       android:background="#659EC7">

    <ImageView android:id="@+id/icon" android:layout_width="72px"
        android:layout_height="wrap_content"
                android:layout_marginTop="5px" />

    <TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
        android:orientation="vertical" 
                android:paddingTop="5px" 
                android:paddingBottom="5px">

        <TextView android:id="@+id/item1" android:layout_width="match_parent"
            android:layout_height="wrap_content" 
                         android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView android:id="@+id/item2" android:layout_width="match_parent"
            android:layout_height="wrap_content" 
                       android:textAppearance="?android:attr/textAppearanceSmall"
            android:paddingTop="30px" />
            <View
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:background="@android:color/darker_gray"/>

    </TwoLineListItem>

</LinearLayout>

我正在使用 2linelistIem

【问题讨论】:

标签: android


【解决方案1】:

使用这种技术来动态改变颜色:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:drawable="@color/black" /> <!-- focused -->
    <item android:state_focused="true" android:state_pressed="true" android:drawable="@color/black" /> <!-- focused and pressed-->
    <item android:state_pressed="true" android:drawable="@color/green" /> <!-- pressed -->
    <item android:drawable="@color/black" /> <!-- default -->
</selector> 

【讨论】:

    【解决方案2】:

    这是我编写和使用的代码: 它为所有其他状态保留了 android 样式。它只是用您想要的颜色覆盖透明状态:

    Layer list drawable for list view with custom background

    正如您在我的问题中看到的,焦点状态存在一个小错误,但它仍然是我见过的最好的解决方案:D

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-10
      • 1970-01-01
      • 2018-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多