Android中自定义TextView的形状

时间:2021-06-15 03:55:45
基本步骤:
在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"