如何为控件添加自定义形状背景

如何为控件添加自定义形状背景

 

版权声明:

本文为博主学习整理原创文章,如有不正之处请多多指教。

未经博主允许不得转载

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"即可

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值