天天看点

【日常新手入门】android之点击变色

实现点击button改变button的颜色只需要在drawable中添加selector.xml文件即可

<selector xmlns:android="http://schemas.android.com/apk/res/android">

        <item android:state_pressed="true"       //点击获取

        android:drawable="@drawable/btn_index_in_normal"/>

         <item

        android:drawable="@drawable/btn_index_in_select"/>

</selector>

注意!正常情况的item要编写在点击事件下面,不然是出现不了点击效果的。

然后在button的background改变为android:background="@drawable/selector1"即可

就能顺利实现按钮点击变色效果了