自定义Shape颜色选择器

<item android:state_selected="true">
    <shape android:shape="rectangle">
        <solid android:color="@color/c_white" />
    </shape>
</item>

<item android:state_pressed="true">
    <shape android:shape="rectangle">
        <solid android:color="@color/c_white" />
    </shape>
</item>
<item android:state_focused="true">
    <shape android:shape="rectangle">
        <solid android:color="@color/c_white" />
    </shape>
</item>
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false">
    <shape android:shape="rectangle">
        <solid android:color="@color/c_bg_e5e5e5" />
    </shape>
</item></selector>

假如最外层是一个LinearLayout线性布局,我需要对整个布局起到点击的效果,在UI没有给图的情况下,除了自己定义颜色选择器后,对LinearLayout的根节点下需要加上如下一行代码,否则起不了点击效果:
android:clickable="true"

    原文作者:追梦小乐
    原文地址: https://www.jianshu.com/p/14173a81fdb0
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞