如何为控件添加自定义形状背景
版权声明:本文为博主原创文章,未经博主允许不得转载。https://mp.csdn.net/postedit/81838711
- 在res/drawable目录下新建shape类型的资源xml文件
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp"/>
<solid android:color="@color/colorPrimary"/>
<stroke android:color="#00000000"/>
</shape>
其中:android:shape指定当前为矩形背景
corners:指定4个角的半径
solid:为填充色
stroke:边框。color为边框颜色,width为边框宽度
2.使用:在xml布局中为需要设置背景的控件设置android:background="@drawable/xxxx"即可