【问题标题】:Selector for list view列表视图的选择器
【发布时间】:2014-01-14 21:40:41
【问题描述】:

我有一个用于列表视图不同状态的选择器。我为背景选择了灰色,但它不工作,按下状态工作正常,但我的列表视图背景仍然是白色,当我选择列表项时,它的颜色变为我为背景和背景选择的灰色仍然是白色的。 请帮忙,对不起这个愚蠢的问题,因为我是安卓新手。 我的列表视图是:

<?xml version="1.0" encoding="utf-8"?>
   <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent" 

   android:background="?android:attr/activatedBackgroundIndicator">


  <ListView
      android:id="@android:id/list"
      android:layout_width="match_parent"
      android:layout_height="match_parent" 
    android:divider="#b5b5b5"
      android:dividerHeight="1dp"
      android:listSelector="@drawable/list_selector">

  </ListView>

        </FrameLayout>

选择器 xml 是:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
     android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/gradient_bg" />
    <item android:state_pressed="true"
        android:drawable="@drawable/gradient_bg_hover" />
    <item android:state_selected="true"
     android:state_pressed="false"
        android:drawable="@drawable/gradient_bg_hover" />
</selector> 

pressed_state xml 是:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
  <gradient
      android:startColor="#78DDFF"
      android:centerColor="#16cedb"
      android:endColor="#09adb9"
      android:angle="270" />
</shape>

背景xml是:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
  <gradient
      android:startColor="#D5DDE0"
      android:centerColor="#e7e7e8"
      android:endColor="#CFCFCF"
      android:angle="270" />
</shape>

【问题讨论】:

    标签: android xml list android-layout selector


    【解决方案1】:

    将您的选择器应用于 ListView 项,我的意思是 row.xml 的视图组或您为列表视图项定义的任何名称。

    【讨论】:

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