简介
TextView控件是一个文本框,经常使用的一个控件。
常用属性
|属性|含义|属性值
|-|-|
|android:text|显示文本|
|android:textColor|文本颜色|"#000000"采用六位十六进制的RGB颜色模式|
|android:textSize|文本大小|通常使用sp作为字体的单位|
|android:textStyle|文本样式|bold表示粗体,italic表示斜体,bolditalic(粗斜体)|
|android:gravity|文本在控件中的位置|可选left,right,top,bottom,center等|
|android:maxLength|文本的长度,超出不显示|
|android:drawableLeft|在文本左侧显示图片|
|android:drawableRight|在文本右侧显示图片|
|android:drawableTop|在文本上面显示图片|
|android:drawableBottom|在文本下面显示图片|
例如:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="200dp"
android:layout_height="50dp"
android:text="hello world"
android:textColor="#FF0000"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="bottom"
android:maxLength="10"
android:drawableLeft="@mipmapic_launcher_round"
/>
</LinearLayout>
![](https://img.haomeiwen.com/i8614581/1d5bba726b47acf1.png)
小技巧
属性的叠加
网友评论