Android 通过solid来定义不同边框的颜色,可以只定义一个边框的颜色

转自:http://blog.csdn.net/aminfo/article/details/7782253

以下是设置按钮的右边框和底边框颜色为红色,边框大小为3dp,如下图:

在drawable新建一个 buttonstyle.xml的文件,内容如下:

[html]   view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">   
  3. <!-- 连框颜色值 --><item>   
  4.       <shape>   
  5.             <solid android:color="#ff0000" />   
  6.       </shape>   
  7. </item>   
  8. <!-- 主体背景颜色值 -->  
  9. <item android:bottom="3dp" android:right="3dp">   
  10.      <shape>   
  11.            <solid android:color="#ffffff" />  
  12.              
  13.            <padding android:bottom="10dp"  
  14.                 android:left="10dp"  
  15.                 android:right="10dp"  
  16.                 android:top="10dp" />  
  17.      </shape>       
  18. </item>  
  19. </layer-list>  

 

然后在布局文件里面的Button里面设置如下:

 

[html]   view plain copy
  1. <Button  
  2.    android:id="@+id/button1"  
  3.    android:layout_width="wrap_content"  
  4.    android:layout_height="wrap_content"  
  5.    android:text="Button1"  
  6.    android:background="@drawable/buttonstyle" />  


 

猜你喜欢

转载自zhousheng193.iteye.com/blog/2176736