安卓TextView文本框与自定义边框

这篇博客详细介绍了在安卓开发中如何自定义TextView的边框,包括常用属性的设置,基本使用方法,以及如何在文本框中添加图片,提供了具体的实现细节。

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

常用属性

z
在这里插入图片描述

自定义边框

在这里插入图片描述

基本使用

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle矩形/ring圆环/oval椭圆/line直线"
    
    当为圆环时
    android:shape="ring"
    android:useLevel="false"如果当作是LevelListDrawable使用时为true,否则为false
    android:innerRadius="10dp"内环半径
    android:innerRadiusRatio="2"浮点型,以环的宽度比来表示内环的半径
    android:thicknessRatio="2"浮点型,以环的宽度比来表示环的厚度
    android:thickness="10dp"环的厚度
>
>
<corners角度
    android:topLeftRadius="10dp"左上角度
    android:topRightRadius="10dp"右上角度
    android:bottomLeftRadius="10dp"左下角度
    android:bottomRightRadius="10dp"/>右下角度
    <stroke描边
        android:width="1dp"线宽度
        android:dashWidth="3dp"虚线宽度
        android:dashGap="3dp"虚线间距
        android:color="@color/purple_200"颜色
        />
        
    <padding android:bottom="5dp"内边距
        android:top="5dp"
        android:left="5dp"
        android:right="50dp"/>
        
    <gradient渐变填充
     android:angle="270"渐变角度,必须为45的倍数,0从左到右,90从上到下
        android:type="sweep扫描式渐变/radia放射渐变/linear线性渐变"
        android:startColor="@color/white"开始颜色
        android:centerColor="@color/grey"中间颜色
        android:endColor="@color/black"结束颜色
         android:centerX="0.6"渐变中心X的相当位置,0--1范围
        android:centerY="0.1"渐变中心Y的相当位置,0--1范围
        android:gradientRadius="5dp"渐变半径,只有radia放射渐变使用
        />
    <size图形大小
        android:width="100dp"宽度
        android:height="100dp"/>高度

</shape>

详细

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

文本框中的图片使用

在这里插入图片描述

具体

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.jay.example.test.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:drawableTop="@drawable/show1"
android:drawableLeft="@drawable/show1"
android:drawableRight="@drawable/show1"
android:drawableBottom="@drawable/show1"
android:drawablePadding="10dp"
android:text="张全蛋" />
</RelativeLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

DQ_CODING

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

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

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

打赏作者

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

抵扣说明:

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

余额充值