今天给大家介绍一下Android Shape Drawable 美化圆角图形,废话不多说,直接上代码

1、首先你得有一个button,在Android xml中直接创建一个控件

android:id="@+id/button1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentTop="true"

android:layout_marginLeft="26dp"

android:layout_marginTop="144dp"

android:text="圆角美化" />

2、在drawable 文件夹中新建一个xml文件,右键->NEW->Android XML File ,取名button,Root Element选择shape,

如图:

0818b9ca8b590ca3270a3433284dd417.png

3、在新建的button.xml中设置属性值

android:radius="4dp" //此属性为圆角的弧度,值越大弧度越大

/>

android:startColor="#cccccc" //开始颜色,#cccccc设置的是灰色

android:centerColor="#cccccc" //中间颜色

android:endColor="#cccccc" //结尾颜色

/>

android:left="7dp"

android:right="7dp"

android:top="7dp"

android:bottom="7dp"

/>

4、剩下的就是在Button控件中引用了,在Button代码中加一句,android:background="@drawable/button"就可以了,运行一下试试,如图:

0818b9ca8b590ca3270a3433284dd417.png

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐