我正在尝试在Lollipop上使用列表视图控件,满足以下条件:
- 主题类型为默认的Theme.Material(深色主题)。
- 列表视图包含在具有白色背景的较大布局中。
- 列表视图应该有一个与白色背景一起显示的列表选择器。
注意:我被迫使用自定义列表选择器颜色,因为如果我使用白色背景,深色材料主题选择器将使用主题的colorControlHighlight颜色作为涟漪效果,其值为40ffffff,不会显示出来。
我首先尝试了以下内容:
layout xml
<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
@id/mask
是什么?我需要在其他地方定义它吗? - poitroae@android:id/mask
。已修正代码示例。 - alanv