2011-11-17 40 views
1

是否有可能使ListView项目的选择颜色以阴影显示(例如左侧)。ListView项目的选择颜色带阴影

我希望左侧的列表项目比右侧的要轻。

+0

yes its poss使用选择器和使用矩形可绘制对他们做一些研发,你会得到答案 –

回答

1

pressed_gradient.xml:(R.drawable.pressed_gradient)

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

listview_selector.xml:(R.drawable.listview_selector)

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

现在在你的XML使用像:

<ListView 
    ... 
    android:listSelector="@drawable/listview_selector" 
    ... 
/>