Android Studio中关于UI控件的边框问题

1.首先在drawable目录中创建一个文件  例如shape.xml

2.可填写内容如下:

 1 <!-- shape定义形状,shape="rectangle"表示形状为长方形 -->
 2 <shape
 3     xmlns:android="http://schemas.android.com/apk/res/android"
 4     android:shape="rectangle" >
 5     <!-- 设置框内填充颜色 -->
 6     <solid android:color="#ffffff" />
 7     <!-- 设置边框宽度和颜色 -->
 8     <stroke
 9         android:width="1dip"
10         android:color="#000000" />
11     <!-- 设置圆角半径 -->
12     <corners android:radius="1dp" />
13     <!-- 设置边距 -->
14     <padding
15         android:bottom="5dp"
16         android:left="5dp"
17         android:right="5dp"
18         android:top="5dp" />
19     <!-- 设置渐变角度angle和渐变颜色 -->
20     <gradient
21         android:angle="270"
22         android:endColor="#FFFF782"
23         android:startColor="#13C7AF" />
24     <!-- 设置各边倒角大小 -->
25     <corners
26         android:bottomLeftRadius="200dp"
27         android:bottomRightRadius="200dp"
28         android:topLeftRadius="0dp"
29         android:topRightRadius="0dp" />
30 </shape>
View Code

3.根据自己所需编写代码

4.例如在Button中调用(将按钮的直角变成圆角):

<Button
    android:background="@drawable/shape" />

 

猜你喜欢

转载自www.cnblogs.com/gxk590281/p/12348654.html