在Android中,有一种特殊的图形,成为shape,在使用图片的地方,基本上可以使用shape,他能实现圆角,边框,渐变等功能。
1、定义圆角shape
在drawable文件夹下新建一个shape_border_color_primary.xml文件

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!--圆角的大小-->
    <!--控件高度的一半-->
    <corners android:radius="20dp"/>

    <!--填充颜色-->
    <!--@android中定义了一些颜色,可以自己查看使用-->
    <solid android:color="@android:color/white"/>

    <!--边框-->
    <stroke
        android:width="1dp"
        android:color="@android:color/holo_blue_bright"/>
</shape>

2、通过控件的background属性引入,实现控件边框效果

<Button
android:background="@drawable/shape_border_color_primary"
android:layout_width="wrap_content"
android:layout_height="40dp"/>
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐