【问题标题】:Highlight of selecte item in Listview in AndroidAndroid中Listview中所选项目的突出显示
【发布时间】:2012-06-23 08:54:22
【问题描述】:

我正在尝试使用selector 突出显示listview 中的选定项目。
当我按下并移动时,一个项目会很好地突出显示。但是,如果我只是单击它,则该项目未突出显示

这是我的选择器:

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

    <item android:drawable="@drawable/item_focused" android:state_pressed="false" android:state_selected="false"/>
    <item android:drawable="@drawable/item_focused" android:state_pressed="true"/>
    <item android:drawable="@android:drawable/item_default" android:state_pressed="false" android:state_selected="true"/>

</selector>

我一直在调查这个问题,但我还没有找到解决方案。

【问题讨论】:

  • 您在列表视图中使用了 android:listSelector 吗?

标签: android android-listview highlighting


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/item_focused" android:state_pressed="true"/>
<item android:drawable="@drawable/item_focused" android:state_focused="true"/>
<item android:drawable="@drawable/item_focused" android:state_selected="true"/>
<item android:drawable="@android:drawable/item_default"/>
</selector>

【讨论】:

  • 谢谢。这是列表视图 XML: schemas.android.com/apk/res/android" android:id="@+id/LinearLayout1" android:layout_width=" match_parent" android:layout_height="match_parent" android:orientation="vertical" >
  • 你能不能尝试从 ListView 中移除 listSelector 属性,并在 ListView 布局中放置一个选择器作为背景。
  • 感谢您的回答。我会试试的。
猜你喜欢
  • 2011-08-16
  • 1970-01-01
  • 2013-04-17
  • 1970-01-01
  • 2013-11-18
  • 1970-01-01
  • 2012-01-23
  • 1970-01-01
  • 2012-01-05
相关资源
最近更新 更多