分享

android:shape的使用

 Babylly 2011-12-08
  1. _selector"  
  2.     />  
  3. >  



  4. button_selector.xml:

XML/HTML代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <selector  
  3.     xmlns:android="http://schemas./apk/res/android">  
  4.     <item android:state_pressed="true" >  
  5.         <shape>  
  6.             <!-- 渐变 -->  
  7.             <gradient  
  8.                 android:startColor="#ff8c00"  
  9.                 android:endColor="#FFFFFF"  
  10.                 android:type="radial"  
  11.                 android:gradientRadius="50" />  
  12.             <!-- 描边 -->  
  13.             <stroke  
  14.                 android:width="2dp"  
  15.                 android:color="#dcdcdc"  
  16.                 android:dashWidth="5dp"  
  17.                 android:dashGap="3dp" />  
  18.             <!-- 圆角 -->  
  19.             <corners  
  20.                 android:radius="2dp" />  
  21.             <padding  
  22.                 android:left="10dp"  
  23.                 android:top="10dp"  
  24.                 android:right="10dp"  
  25.                 android:bottom="10dp" />  
  26.         </shape>  
  27.     </item>  
  28.     <item android:state_focused="true" >  
  29.         <shape>  
  30.             <gradient  
  31.                 android:startColor="#ffc2b7"  
  32.                 android:endColor="#ffc2b7"  
  33.                 android:angle="270" />  
  34.             <stroke  
  35.                 android:width="2dp"  
  36.                 android:color="#dcdcdc" />  
  37.             <corners  
  38.                 android:radius="2dp" />  
  39.             <padding  
  40.                 android:left="10dp"  
  41.                 android:top="10dp"  
  42.                 android:right="10dp"  
  43.                 android:bottom="10dp" />  
  44.         </shape>  
  45.     </item>  
  46.     <item>        
  47.         <shape>  
  48.             <solid android:color="#ff9d77"/>  
  49.             <stroke  
  50.                 android:width="2dp"  
  51.                 android:color="#fad3cf" />  
  52.             <corners  
  53.                 android:topRightRadius="5dp"  
  54.                 android:bottomLeftRadius="5dp"  
  55.                 android:topLeftRadius="0dp"  
  56.                 android:bottomRightRadius="0dp"  
  57.             />  
  58.             <padding  
  59.                 android:left="10dp"  
  60.                 android:top="10dp"  
  61.                 android:right="10dp"  
  62.                 android:bottom="10dp" />  
  63.         </shape>  
  64.     </item>  
  65. </selector>  


运行效果如下图:
一般状态:


获得焦点状态:


按下状态:


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约