博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何实现button点击时,按钮变色
阅读量:7080 次
发布时间:2019-06-28

本文共 1427 字,大约阅读时间需要 4 分钟。

hot3.png

需要建立三个xml

   button_background_selected.xml

   normal_entry_dialog.xml

   button_selector.xml

 

其中drawable中的button_selector.xml中代码为

<?xml version="1.0" encoding="utf-8"?>

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

 

    <item android:drawable="@drawable/button_background" android:state_enabled="true" android:state_window_focused="false"/>

    <item android:drawable="@drawable/button_background_selected" android:state_pressed="true"/>

    <item android:drawable="@drawable/button_background" android:state_focused="true"/>

    <item android:drawable="@drawable/button_background"/>

 

</selector>

 

Drawable中的button_background_selected.xml代码

<?xml version="1.0" encoding="utf-8"?>

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

    android:shape="rectangle" >

    <corners android:radius="2dip" >

    </corners>

    <gradient android:startColor="#ff00fea1"

        android:centerColor="#ff00ff21"

        android:endColor="#ff00fea1"

        />

</shape>

 

Layout中的normal_entry_dialog.xmlbutton按钮

        <Button

            android:id="@+id/bt_normal_dialog_ok"

            android:layout_width="140dip"

            android:layout_height="40dip"

            android:background="@drawable/button_selector"

            android:text="确定" />

 

        <Button

            android:id="@+id/bt_normal_dialog_cancle"

            android:layout_width="140dip"

            android:layout_height="40dip"

            android:layout_marginLeft="5dip"

            android:background="@drawable/button_selector"

            android:text="取消" />

</LinearLayout>

转载于:https://my.oschina.net/zhiaiyafang/blog/649874

你可能感兴趣的文章
Delphi XE2 之 FireMonkey 入门(18) - TLang(多语言切换的实现)
查看>>
学用 ASP.Net 之 System.DateTime 结构
查看>>
我的友情链接
查看>>
互联网枭雄点评之周鸿祎 - 不甘老去的互联网老兵
查看>>
PKI_IOS证书加密L2L ×××
查看>>
web基础
查看>>
Apache和Nginx的区别
查看>>
2017.5.23 MS Power BI workshop for partner
查看>>
翻译连载 |《你不知道的JS》姊妹篇 |《JavaScript 轻量级函数式编程》- 第 8 章:列表操作...
查看>>
Linux常用的系统监控shell脚本
查看>>
Android Studio中使用GreenDao
查看>>
Yii 框架之采用自带的jquery库实现ajax分页
查看>>
Android广播-个人总结
查看>>
Mybatis 框架源码分析
查看>>
关于 LF will be replaced by CRLF 问题出现的原因以及解决方式
查看>>
HTML5编程之旅 第3站 WebSockets
查看>>
oracle 体系结构及内存管理 05_重建EM
查看>>
everedit
查看>>
改写源代码,使得认证成功后跳转到successUrl路径
查看>>
浅析CentOS和RedHat Linux的区别
查看>>