Android 设置背景边框

摘自: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" />


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部