我有一個RelativeLayout的爲什麼我的RelativeLayout不使用選擇器?
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:background="@drawable/animated_bg">
,我已經定義了一個選擇
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/ripple_color">
<item>
<selector>
<item android:state_pressed="true"
android:drawable="@color/grey_1" />
<item android:state_focused="true"
android:drawable="@color/grey_1" />
<item android:drawable="@color/white" />
</selector>
</item>
但是當我按下佈局不改變顏色。
任何人都可以注意到爲什麼會發生這種情況?
更新
下面是完整的XML文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:background="@drawable/animated_bg">
<RelativeLayout>
<RelativeLayout>
<ImageView />
<LinearLayout>
<TextView />
<TextView />
</LinearLayout>
</RelativeLayout>
<LinearLayout >
<LinearLayout >
<RelativeLayout >
<ImageView />
<TextView />
<TextView />
<TextView />
</RelativeLayout>
<RelativeLayout >
<ImageView />
<TextView />
<TextView />
</RelativeLayout>
</LinearLayout>
<LinearLayout >
<RelativeLayout >
<TextView />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
似乎一般建議在選擇器中使用構建,除非您想要自定義顏色。強烈建議用'attr/selectableItemBackground'替換'@ drawable/animated_bg'' –