我在适配器项目中使用 ConstraintLayout 作为根(使用 RecyclerView)。我的问题是我无法使选择器在棒棒糖之前的设备上工作。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="@dimen/material_cell_height"
android:foreground="@drawable/selector_cell"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textview_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="@dimen/material_content_padding"
android:paddingStart="@dimen/material_content_padding"
android:textAppearance="@style/TextAppearance.Cell.Body2"
android:transitionName="@string/transition_toolbar"
android:translationZ="1dp"
app:layout_constraintBottom_toTopOf="@+id/textview_author"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/btn_overflow"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:ignore="UnusedAttribute,NewApi,RtlSymmetry,PrivateResource"
tools:text="The Best Product" />
<TextView
android:id="@+id/textview_author"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="@dimen/material_content_padding"
android:paddingStart="@dimen/material_content_padding"
android:textAppearance="@style/TextAppearance.Cell.Body"
android:translationZ="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textview_title"
tools:text="John Doe and Band" />
<ImageView
android:id="@+id/imageview_cover"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:scaleType="centerCrop"
android:translationZ="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@mipmap/ic_launcher" />
<ImageButton
android:id="@+id/btn_overflow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:translationZ="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/textview_title"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_more_vert_black_24px" />
</android.support.constraint.ConstraintLayout>
这是我的棒棒糖前设备选择器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/transparent" android:state_window_focused="false" />
<item android:drawable="@color/cell_touch_effect" android:state_checked="true" />
<item android:drawable="@color/cell_touch_effect" android:state_activated="true" />
<item android:drawable="@color/cell_touch_effect" android:state_selected="true" />
</selector>
有什么建议可以解决这个问题吗?