1.TextView:用来显示字符串的组件,在手机上就是显示一块文本的区域。
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Hello World! 你好,世界!Hello World! 你好,世界!Hello World! 你好,世界!"
android:textSize="20sp"
android:textColor="#f00"
android:hint="这是提示语(text文本为空或没有的时候提示语才显示)"
android:singleLine="true"
android:background="#5500ffee"
android:inputType="textPassword"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
知识点:
(1)表示宽度和高度的三种方式:
①match_parent 全部占满 ②wrap_content 自适应 ③100dp 具体的数值
(2)android:background="#5500ffee" 前两位表示透明度,后六位表示RGB颜色;背景也可以设置为图片
(3)android:singleLine=“true” 设置TextView显示一行,未显示部分打点(…)表示
(4)android:lines=“3” 设置TextView的行数
拓展:android:lines=“1”
android:ellipsize=“end”
以上两句可以实现与 android:singleLine=“true” 一样的效果
(5)android:inputType=“textPassword” 设置TextView为密码显示方式,将以点的形式代表字符
还有一种过时的表示方式:android:password=“true”
(6)android:text=“www.baidu.com”
android:autoLink=“web”
以上两句可以实现链接,点击可跳转
拓展:
在TextView 中设置autoLink 属性可以自动识别Web URL、电话号码、电子邮件地址、添加下划线改变字体颜色并实现点击事件,支持自动识别的类型:
android:autoLink=“web” 匹配Web URL。
android:autoLink=“phone” 匹配电话号码
android:autoLink=“email” 匹配电子邮件地址
android:autoLink=“map” 匹配地理位置
android:autoLink=“all” 匹配所有可用的模式
android:autoLink=“none” 不匹配任何类型
也可以类似这样的设