Android Button特效selector+shape

    玩了将近一个月的android,确实感觉它的强大,考虑的也是非常全啊,连一个小小的button都能做的这么华丽,真不是展讯平台可以相比的。如果感觉用ImageButton的也可以按这样的结果下来。下面是我转载过来的文章,方便忘记的时候过来看看
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <selector
  3.    xmlns:android="http://schemas.android.com/apk/res/android">
  4.    <item android:state_pressed="true" >
  5.      <shape>
  6.         <gradient
  7.            android:startColor="#ff8c00"
  8.            android:endColor="#FFFFFF"
  9.            android:angle="270" />
  10.         <stroke
  11.            android:width="2dp"
  12.            android:color="#dcdcdc" />
  13.         <corners android:radius="2dp" />
  14.         <padding
  15.             android:left="10dp"
  16.             android:top="10dp"
  17.             android:right="10dp"
  18.             android:bottom="10dp" />
  19.       </shape>
  20.    </item>

  21.    <item android:state_focused="true" >
  22.       <shape>
  23.          <gradient
  24.            android:startColor="#ffc2b7"
  25.            android:endColor="#ffc2b7"
  26.            android:angle="270" />
  27.            
  28.          <stroke
  29.           android:width="2dp"
  30.           android:color="#dcdcdc" />

  31.          <corners android:radius="2dp" />

  32.          <padding
  33.           android:left="10dp"
  34.           android:top="10dp"
  35.           android:right="10dp"
  36.           android:bottom="10dp" />

  37.       </shape>
  38.   </item>

  39.   <item>
  40.       <shape>
  41.          <gradient
  42.             android:startColor="#F8F8FF"
  43.             android:endColor="#F8F8FF"
  44.             android:angle="270" />
  45.          <stroke
  46.             android:width="2dp"
  47.             android:color="#F8F8FF" />
  48.          <corners
  49.             android:radius="2dp" />
  50.          <padding
  51.             android:left="10dp"
  52.             android:top="10dp"
  53.             android:right="10dp"
  54.             android:bottom="10dp" />
  55.      </shape>
  56.   </item>
  57.   
  58. </selector>
    上面代码就可以定义个完整的Button的shape了。以上几个item的区别主要是体现在state_pressed按下或state_focused获得焦点时,当来判断显示什么类型,而没有state_xxx属性的item可以看作是常规状态下。在gradient中startcolor属性为开始的颜色,endcolor为渐变结束的颜色,下面的angle是角度。接下来是stroke可以理解为边缘,corners为拐角这里radius属性为半径,最后是相对位置属性padding。
 
    然后只需在你得Button布局文件里添加这句android:background="@drawable/button_change"(button_change为我上面程序的xml文件)
    这里还有android许多颜色的RGB值 http://apps.hi.baidu.com/share/detail/34164477
<script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/buttonLite.js#style=-1&uuid=&pophcol=3&lang=zh"></script> <script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/bshareC0.js"></script>
阅读(1368) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值