android 关于美化按钮的小技巧

来源:互联网 发布:河池论坛网络问政电话 编辑:程序博客网 时间:2024/05/16 00:25

通过创建xml文件来实现

1.创建按钮背景white.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" >    <corners android:radius="5dp"/>    <solid android:color="@color/white"/></shape>

2.再创建按钮被按下的背景grey.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" >    <corners android:radius="5dp"/>    <solid android:color="@color/grey"/></shape>

3.再创建最后一个btn_bg.xml

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/grey" android:state_pressed="true"/>    <item android:drawable="@drawable/white"/></selector>


以上就是通过用btn_bg.xml做为背景的效果(颜色是通过创建color.xml,然后引用的)

0 0
原创粉丝点击