Android中drawable给View设置上下左右边框

1.在drawable文件夹下新建一个shape_main_list_bg.xml文件

[html]  view plain  copy
  1. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >  
  2.     <!-- This is the main color -->  
  3.     <item>  
  4.         <shape>  
  5.                 <!--    边框颜色 -->  
  6.             <solid android:color="#00FF00"/>  
  7.         </shape>  
  8.     </item>  
  9.     <!-- 给View的上 左  右设置8dp的边框 -->  
  10.     <item android:top="8dp" android:left="8dp" android:right="8dp" >  
  11.         <shape>  
  12.                 <!--     View填充颜色 -->  
  13.             <solid android:color="#FFFFFF" />  
  14.         </shape>  
  15.     </item>  
  16.   
  17. </layer-list>  



2.给控件设置背景

[html]  view plain  copy
  1. <EditText  
  2.     android:padding="20dp"  
  3.     android:layout_margin="15dp"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="wrap_content"  
  6.     android:hint="请输入Edittext内容"  
  7.     android:background="@drawable/shape_main_list_bg"/>  


3.效果图如下:

  


猜你喜欢

转载自blog.csdn.net/zjy_android/article/details/79487799