我是
Android开发的新手.我正在尝试开发适用于Android的短信应用.我成功阅读了收件箱和联系人,并在ListView项目中显示它们.现在,我想要实现的是每次点击或触摸或选择这些ListView项目时都会产生连锁反应.我使用listSelector但似乎它不起作用.如果有人可以帮助我,下面是我的代码:
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ListView
android:id="@+id/msglist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="true"
android:listSelector="#777777" />
解决方法
你打算在适配器中为ListView扩充一个布局,对吧?然后你可以转到那个layout.xml并将android:background =“?android:selectableItemBackground”设置为根元素.
注意:这样做只能在API 21(Lollipop)之上发生连锁反应.在Lollipop下,当您触摸该项目时,将出现一个透明的蓝色图层并覆盖您的源内容,这将显示为选择状态.