圆角边框,渐变背景的Textview

在默认情况下,TextView是不带边框的,如果想为Textview添加边框,只能通过为它设置一个背景Drawable,改Drawble只是一个边框,这样就实现了带边框的TextView

第一步:创建shape XML文件 border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <!--设置背景颜色为橙色-->
<solid android:color="#daa447"></solid>
    <!--设置边框颜色为红色-->
    <stroke android:width="4dp" android:color="#f00"></stroke>
</shape>

 

第二步 在TextView中引入背景border.xml

<TextView
    android:textSize="50sp"
    android:background="@drawable/border"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="带边框的文本" />

效果图如下:

 

设置圆角渐变的TextView

第一步:在Drawable创建bg.xml 文件

如下所示

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!--设置圆角的半径-->
    <corners android:radius="50dp"></corners>

    <!--指定使用渐变背景色 颜色从红色-绿色-蓝色-->
    <gradient
        android:centerColor="#0f0"
        android:endColor="#00f"
        android:startColor="#f00"></gradient>
</shape>

第二步:在TextView中引入

<TextView
    android:textSize="50sp"
    android:background="@drawable/bg1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="圆角渐变" />

效果图如下:

圆弧按钮 drawable目录下创建 shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <!-- 填充的颜色 -->
    <solid android:color="#E4B17A" />

    <!-- 设置按钮的四个角为弧形 -->
    <!-- android:radius 弧形的半径 -->
    <corners android:radius="25dip" />

    <!-- padding:Button里面的文字与Button边界的间隔 -->
    <padding
        android:bottom="10dp"
        android:left="10dp"
        android:right="10dp"
        android:top="10dp" />
</shape>

引入

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:background="@drawable/shape"
        android:text="查询" />

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Chen_ShengJie

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值