textEdit可以添加背景图片、渐变色、文字颜色、大小等等

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!--设置字号为20pt,在文本末尾绘制图片--> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World!" android:textSize="20pt" android:drawableEnd="@mipmap/ic_launcher" android:drawableRight="@mipmap/ic_launcher" /> <!--设置中间省略,所有字母大写--> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="middle" android:textAllCaps="true" android:text="学习Android学习Android学习Android学习Android学习Android学习Android学习Android" /> <!--设置文字颜色、大小、使用阴影--> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="测试文字" android:shadowColor="#00f" android:shadowDx="10.0" android:shadowDy="8.0" android:shadowRadius="3.0" android:textColor="#ff0" android:textSize="18pt" /> <!--设置可勾选文本--> <CheckedTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="可勾选的文本" android:checkMark="@drawable/ok" /> <!--指定背景--> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="带边框的文本" android:textSize="24pt" android:background="@drawable/bg_border" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="圆角边框,渐变背景" android:textSize="24pt" android:background="@drawable/bg_border2" /> </LinearLayout> </ScrollView>

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!--设置背景色为透明--> <solid android:color="#0000"/> <!--设置红色边框--> <stroke android:width="2dp" android:color="#f00"/> </shape>

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!--指定4个圆角的半径--> <corners android:topLeftRadius="20dp" android:topRightRadius="10dp" android:bottomLeftRadius="20dp" android:bottomRightRadius="10dp" /> <!--指定边框线条的宽度和颜色--> <stroke android:color="#f0f" android:width="4px"/> <!--指定渐变色--> <gradient android:startColor="#f00" android:centerColor="#0f0" android:endColor="#00f" android:type="sweep"/> </shape>