Android中自定义TextView的形状

本文介绍如何在Android应用中创建自定义样式的按钮,包括使用shape XML实现圆形和圆角按钮的方法,并展示了如何将这些样式应用于TextView组件。
基本步骤:
在drawable文件夹下建立一个shape.xml

shape.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
              android:shape="oval">
    <!-- 填充的颜色 -->
    <solid android:color="#FF8C2E"/>
     <!-- 设置按钮的四个角为弧形 -->
     <!-- android:radius 弧形的半径 -->
     <corners android:radius="360dip"/>
     <!-- padding: Button 里面的文字与Button边界的间隔 -->
     <padding
        android:left="10dp"
        android:top="10dp"
        android:right="10dp"
        android:bottom="10dp"
    />
    
</shape>
在主界面中的main.xml:
<pre name="code" class="html">
                <TextView
                 android:id="@+id/agree"
                 android:layout_width="125dp"
                 android:layout_height="50dp"
                 android:background="@drawable/shape"
                 android:gravity="center"
                 android:text="审批通过"
                 android:textColor="@color/black"
                 android:textSize="20sp" />
                <TextView
                 android:id="@+id/disagree"
                 android:layout_width="125dp"
                 android:layout_height="50dp"
                 android:background="@drawable/shape"
                 android:gravity="center"
                 android:text="审批不通过"
                 android:textColor="@color/black"
                 android:textSize="20sp" />


注意:在shape文件中,

表示绘制椭圆:

 android:shape="oval"

表示绘制线条:

android:shape="line"
表示绘制矩形;加上半径,则可以绘制圆角矩形。

android:shape="Rectange"



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值