1. 程式人生 > >Linerlayout background selector無效解決方法

Linerlayout background selector無效解決方法

Linerlayout xml屬性:

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_white_to_gray"
        android:orientation="horizontal">

selector xml屬性:

    <?xml version="1.0" encoding="utf-8"?>
    <selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorAccent" android:state_pressed="true"/> <item android:drawable="@color/colorPrimary"/> </selector>

發現並沒有什麼卵用

需要在Linerlayout xml屬性加上一句

    android:clickable="true"