2013-03-07 102 views
0

我幾乎是Android開發方面的noob,我試圖突出顯示一個列表視圖項目,就像在大多數全屏應用程序中看到的那樣,但它對我而言並不適用。如何在列表視圖項目上啓用突出顯示

我的XML代碼是在這裏

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

<ListView android:id="@android:id/list" 
    android:scrollX="10.0dip" 
    android:background="#DDDDDD" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="10.0dip" 
    android:layout_marginTop="10.0dip" 
    android:layout_marginBottom="10.0dip" 
    android:stackFromBottom="true" 
    android:soundEffectsEnabled="true" 
    android:listSelector="#0eBFE9" 
/> 

的問題是,當選擇在我的ListView中的項目不突出。要完成它的唯一方法是使用

android:drawSelectorOnTop = "true" 

但是,然後文本在選擇時被隱藏。該應用程序僅適用於v4.0 +,如果有幫助的話。

回答

1

對於突出顯示ListView的列表項,您需要使用 選擇器概念。

<?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="@color/normal" /> 
<item android:state_pressed="true" 
    android:drawable="@color/itemselectedcolor" /> 
<item android:state_selected="true" 
android:state_pressed="false" 
    android:drawable="@color/itemselectedcolor" /> 
</selector> 

欲瞭解更多詳情,請瀏覽我的Android博客。你會發現如何在列表項父佈局中使用選擇

http://amitandroid.blogspot.in/2013/03/android-listview-with-alternate-list.html

感謝,

+0

OMG!非常感謝!我不敢相信我在挫折中度過了這麼多小時,解決方案非常簡單! – TheDareDevil 2013-03-07 10:13:46

相關問題