代码改变世界

android button 点击时改变颜色(2)

2017-11-13 20:54  darling达  阅读(1660)  评论(0)    收藏  举报

1.通过shape进行转换

效果图 平时:   单击时 

2.设置一个button

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_selectors"/>

3.在drawable下新建shape_normal.xml和shape_pressed.xml两个文件

4.分别打开两个xml文件编写代码

 

5.在button_selector.xml中指定资源文件,运行即可!