Android 列表视图设置自定义涟漪选择器
我尝试在以下条件下对棒棒糖使用列表视图控件:Android 列表视图设置自定义涟漪选择器,android,android-listview,android-5.0-lollipop,Android,Android Listview,Android 5.0 Lollipop,我尝试在以下条件下对棒棒糖使用列表视图控件: 主题类型是默认的theme.Material(暗主题) 列表视图包含在具有白色背景的较大布局中 列表视图应有一个以白色背景显示的列表选择器 注意:我被迫使用自定义列表选择器颜色,因为如果我使用白色背景,黑色材质主题选择器将使用主题的colorControlHighlight颜色作为涟漪,即40ffffff,并且不会显示 我首先尝试了以下方法: 布局xml <LinearLayout android:layout_width="match
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@android:color/white" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:listSelector="@drawable/list_selector" />
</LinearLayout>
列表选择器xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ff0000" >
</ripple>
和列表视图行xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal"
tools:ignore="UseCompoundDrawables" >
<ImageView
android:id="@+id/list_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/list_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
我希望看到的是,当我选择一个项目时,该项目会被选择为带有波纹的颜色#ff0000。然而,我最终看到的是:
我所希望的是有点接近这种行为-但限制在选定的列表行内!我做错了什么
谢谢,
Zach您使用的是一个无限波纹,例如没有内容或遮罩层的波纹,因此波纹投影到其父ListView的背景上。应设置遮罩层以约束波纹边界 res/drawable/my_list_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item android:id="@android:id/mask">
<color android:color="@color/white" />
</item>
</ripple>
谢谢你!今天又是一个很好的回答(你早些时候帮我提出了另一个ripple问题!)。非常感谢。什么是@id/mask
?我需要在其他地方定义它吗?应该是@android:id/mask
。修正了代码示例。加入感恩的人)谢谢,alanv