2012-07-24 34 views
0

我有两个形状是这样的:列表选择Android的

List_selector_focused.xml

<gradient 
    android:startColor="#f5c98c" 
    android:endColor="#f7ddb8" 
    android:angle="90" /> 

</shape> 

list_selector_pressed.xml

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

<gradient 
    android:startColor="#fb9d23" 
    android:endColor="#ffc579" 
    android:angle="90" /> 

</shape> 

和我list_selector。 xml

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

<item 
    android:state_pressed="true" 
    android:drawable="@drawable/list_selector_pressed" /> 

<item 
    android:state_focused="true" 
    android:drawable="@drawable/list_selector_focused" /> 

<item 
    android:drawable="@android:color/transparent" /> 

</selector> 

和我的列表视图,我添加了list_selector.xml

<ListView 
    android:id="@+id/list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#000000" 
    android:cacheColorHint="#0A3A5C" 
    android:scrollbars="none" 
    android:listSelector="@drawable/list_selector"> 

但有出现,当我按在ListView的项目之一,有什么建议没有颜色?

编辑

我尝试将其应用到列表中,是一个自定义列表。列表中每个项目的布局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:paddingBottom="10dip" 
android:paddingLeft="10dip" 
android:paddingTop="10dip" > 

<TextView 
    android:id="@+id/idNumber" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="First" 
    android:textColor="#11629F" 
    android:textSize="17sp" 
    android:textStyle="bold" /> 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

</LinearLayout> 

<TextView 
    android:id="@+id/date" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/idNumber" 
    android:layout_below="@+id/idNumber" 
    android:text="Second" 
    android:textSize="15sp" /> 
</RelativeLayout> 
+0

什么'@android:color/transparent','@ drawable/list_selector_focused'和'@ drawable/list_selector_pressed'包含? – Praveenkumar 2012-07-24 07:58:45

+0

对不起,我的坏。看我的编辑:) – 2012-07-24 08:01:17

+0

@Tobias Moe Thorstensen尝试两件事。首先:将你的listiew clickable和longClickable属性设置为true并报告。其次:尝试通过registerForContextMenu()注册yout listview的contextmenu。如果你必须实现哑听者。报告你的发现。 – Anderson 2013-09-18 11:54:08

回答

2

您的物品是否具有恒定的背景颜色?如果是这样,您的选择器将不会显示,因为此选择器设置在您的项目背面。确保您的项目背景在选中时是透明的,以便让您的选择器可见。

+0

什么项目?列表中的项目?我应该在哪里指定? – 2012-07-24 08:04:14

+0

在这些项目的XML中,在您的布局文件夹下。或者,您是否在使用Android平台提供的资源?我不确定这是否是解决问题的方法,但可能是。 – 2012-07-24 08:08:44

+0

请看我的编辑,这是你的意思吗? :) – 2012-07-24 08:13:06