我有两个形状是这样的:列表选择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>
什么'@android:color/transparent','@ drawable/list_selector_focused'和'@ drawable/list_selector_pressed'包含? – Praveenkumar 2012-07-24 07:58:45
对不起,我的坏。看我的编辑:) – 2012-07-24 08:01:17
@Tobias Moe Thorstensen尝试两件事。首先:将你的listiew clickable和longClickable属性设置为true并报告。其次:尝试通过registerForContextMenu()注册yout listview的contextmenu。如果你必须实现哑听者。报告你的发现。 – Anderson 2013-09-18 11:54:08