圆角风格Button

本文详细介绍如何通过XML定义圆角矩形样式,并应用于按钮背景,包括设置填充颜色、圆角半径、边框线及渐变效果,实现美观且具交互性的圆角按钮。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

圆角风格的按钮实际山就是一个带有圆角的背景,可以通过设置按钮的背景图片来实现

效果

  • 画一个圆角的矩形
<?xml version="1.0" encoding="utf-8"?>
<!-- android:shape="rectangle" 设置长方形几何图形 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <!-- 填充颜色 -->
    <solid android:color="#09f" />
    <!-- 设置四个角为弧形,指定弧形半径 -->
    <corners android:radius="5dip" />
    <!-- 设置按钮边框与文字之间间隔  -->
    <padding
        android:bottom="10dp"
        android:left="10dp"
        android:right="10dp"
        android:top="10dp" />
</shape>
  • 设置按钮的背景为圆角矩形
   <!-- 指定按钮的背景属性 -->
	<Button 
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	   	android:background="@drawable/shape"
	    android:text="圆角风格的按钮"/>

背景渐变

  • 设置背景渐变
 <gradient
        android:endColor="#3F51B5"
        android:startColor="#FF4081" />

设置边框线

  • 设置边框线
 <stroke
        android:width="3dp"
        android:color="#003399" />

单独设置四角弧度

  • 单独指定四角弧度
<shape xmlns:android="http://schemas.android.com/apk/res/android" >  
    <corners android:topLeftRadius="30dp" android:bottomLeftRadius="30dp"  
        android:topRightRadius="0dp" android:bottomRightRadius="0dp"/>  
    <solid android:color="#ff0000"/>  
</shape>  

类似圆角 控件也可使用此方法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值