点击事件加上颜色的点击效果

来源:互联网 发布:数据运营专员做什么的 编辑:程序博客网 时间:2024/05/16 11:51

在项目中为了美观,通常都会加上事件的点击效果,加图片很简单打,但是有时候应为特殊需求要加点击时的颜色效果,便记下来方法,以备不时之需

首先跟加图片的背景一样,在drawable里建一个xml文件

内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">


    <item android:state_pressed="true"><shape>
            <gradient android:endColor="@color/yellow" android:startColor="@color/yellow" />
        </shape></item>
    <item android:state_focused="true"><shape>
            <gradient android:endColor="@color/yellow" android:startColor="@color/yellow" />
        </shape></item>
    <item android:state_checked="true"><shape>
            <gradient android:endColor="@color/yellow" android:startColor="@color/yellow" />
        </shape></item>
    <item android:state_selected="true"><shape>
            <gradient android:endColor="@color/yellow" android:startColor="@color/yellow" />
        </shape></item>
    <item><shape>
            <gradient android:endColor="@color/background" android:startColor="@color/background" />
        </shape></item>
    
</selector>

0 0
原创粉丝点击