Android 实现各种形状和颜色的按钮

Android 实现各种形状的按钮

上一篇 设置透明按钮和自定义背景 这里就不过多讲解 具体是这么设置的,这篇文章主要分享 各种形状和颜色的按钮。
形状1:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 设置固定填充色 -->
<solid android:color="#f00" /> //颜色可以自己设定
<size android:width="60dp" android:height="30dp"/>
</shape>

看一下效果:
在这里插入图片描述
形状2:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <size android:width="60dp" android:height="30dp"/>
    <!-- 设置渐变填充色 -->
    <gradient android:startColor="#00f" android:centerColor="#0f0" android:endColor="#f00"></gradient>
</shape>

在这里插入图片描述
形状3:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <size android:width="60dp" android:height="30dp"/>
    <!-- 设置描边 -->
    <stroke 
        android:width="2dp" 
        android:color="#f00" >
    </stroke>
</shape>

在这里插入图片描述
形状4:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<size android:width="60dp" android:height="30dp"/>
<!-- 设置描边 -->
	<stroke
		android:width="2dp" 
		android:color="#f00" 
		android:dashWidth="5dp"
		android:dashGap="5dp">
	</stroke>
</shape>

在这里插入图片描述
形状5:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <size android:width="60dp" android:height="30dp"/>
    <!-- 设置描边 -->
    <stroke 
        android:width="2dp" 
        android:color="#f00" 
        android:dashWidth="5dp" 
        android:dashGap="5dp"></stroke>
    <corners android:radius="15dp"/>
</shape>

在这里插入图片描述
形状6:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- 设置固定填充色 -->
    <solid android:color="#f00" />
    <size 
        android:width="60dp" 
        android:height="30dp"/>
    <corners android:radius="10dp"/>
</shape>

在这里插入图片描述
形状7:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <size android:width="60dp" android:height="30dp"/>
    <!-- 设置渐变填充色 -->
    <gradient 
        android:startColor="#f00" 
        android:centerColor="#0f0" 
        android:endColor="#00f" 
        android:gradientRadius="60"
        android:type="radial"></gradient>
</shape>

在这里插入图片描述
形状8:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <size android:width="60dp" android:height="30dp"/>
    <!-- 设置描边 -->
    <stroke android:width="2dp" android:color="#FFBB86FC" ></stroke>
    <corners android:radius="15dp"/>
</shape>

在这里插入图片描述
形状9:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <size android:width="60dp" android:height="30dp"/>
    <!-- 设置渐变填充色 -->
    <gradient android:startColor="#4169E1"
        android:centerColor="#D2691E"
        android:endColor="#87CEFA"
        android:type="sweep">

    </gradient>
</shape>

在这里插入图片描述
形状10:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <size android:width="60dp" android:height="30dp"/>
    <!-- 设置描边 -->
    <stroke 
        android:width="2dp" 
        android:color="#f00" 
        android:dashWidth="5dp" 
        android:dashGap="5dp">
    </stroke>
    <corners 
        android:radius="15dp" 
        android:topRightRadius="0dp" 
        android:bottomRightRadius="0dp"/>
</shape>

在这里插入图片描述
形状11:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <!-- 设置固定填充色 -->
    <solid android:color="#48D1CC" />
    <size android:width="60dp" android:height="30dp"/>
</shape>

在这里插入图片描述
形状12:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <size android:width="60dp" android:height="30dp"/>
    <!-- 设置渐变色 -->
    <gradient 
        android:startColor="#00f" 
        android:centerColor="#0f0" 
        android:endColor="#f00"></gradient>
</shape>

在这里插入图片描述
形状13:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <size android:width="60dp" android:height="30dp"/>
    <!-- 设置描边色 -->
    <stroke
        android:width="2dp"
        android:color="#f00" >
    </stroke>
</shape>

在这里插入图片描述
形状14:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <size android:width="60dp" android:height="30dp"/>
    <!-- 设置描边色 -->
    <stroke 
        android:width="2dp" 
        android:color="#f00" 
        android:dashWidth="5dp" 
        android:dashGap="5dp">
    </stroke>
</shape>

在这里插入图片描述
形状15:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="20dp"
    android:shape="ring"
    android:thickness="2dp"
    android:useLevel="false" >
    <!-- 设置固定填充色 -->
    <solid android:color="#f00" />
    <size
        android:height="20dp" />
</shape>

在这里插入图片描述
形状16:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="20dp"
    android:shape="ring"
    android:thickness="2dp"
    android:useLevel="false" >
    <!-- 设置渐变填充色 -->
    <gradient 
        android:startColor="#00f" 
        android:centerColor="#0f0" 
        android:endColor="#f00"/>
    <size
        android:height="44dp"/>
    <stroke 
        android:width="2dp" 
        android:color="#f00" 
        android:dashWidth="5dp" 
        android:dashGap="5dp"/>
</shape>

在这里插入图片描述
形状17:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >
    <stroke
        android:dashGap="8px"
        android:dashWidth="8px"
        android:width="1dp"
        android:color="#f00" />
    <size android:height="30dip" />
</shape>

在这里插入图片描述

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值