Android button 圆角

以前一直遇到各种button圆角的需求,然后不会  只能找美工切图,然后在android:background="" 然后吧背景图放进去,取巧的办法。
找了个时间看了看button的圆角做法,记录下;

在drawble文件夹创建一个xml文件:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

    <!-- 背景色-->
    <solid android:color="#ff00ffff"/>
    <!-- 圆角-->
    <corners android:radius="30dp"/>
    <!--设置边框线的宽度和颜色-->
    <stroke android:width="3dp" android:color="@color/colorPrimaryDark"/>

    <padding
        android:bottom="15dp"
        android:left="15dp"
        android:right="20dp"
        android:top="10dp"
        />
        <!-- 在这里写的代码,是指那种特殊要求,圆角下面的那句代码可以注释掉,如果用这种-->
    <corners android:topRightRadius="40dp"
        android:topLeftRadius="100dp"
        android:bottomLeftRadius="40dp"
        android:bottomRightRadius="30dp"/>

</shape>

每个都有注释 。


     <corners android:topRightRadius="40dp"   //这句话的意思是右上角的圆角
        android:topLeftRadius="100dp"         //左上角的圆角
        android:bottomLeftRadius="40dp"       //左下角的圆角
        android:bottomRightRadius="30dp"/>    //右下角的圆角

每个圆角都可以单独使用。当然 看需求做吧

<padding
        android:bottom="15dp"  //向下15dp
        android:left="15dp"   //左15dp
        android:right="20dp"
        android:top="10dp"
        />

这个 可以自己调下dp大小就知道是做什么的了
android:drawableTop
android:drawableBottom
android:drawableLeft
android:drawableRight 这四个值表示引入图片,且该图片与文字排列的规则

引用一篇文章,这个文章详细的有写Android中shape的使用

https://blog.csdn.net/ekeuy/article/details/12349853

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值