【Android】入门04:TextView

 

目录

TextView:文本展示标签

1.使用文本资源

2.常用属性

3.文字省略

4.文字链接


TextView:文本展示标签

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

 

1.使用文本资源

使用文本资源,可以规范app中的文本,可以使用国际化...

在下面目录中的strings.xml文件中添加一个文本资源。

使用 @string 来引用文本资源

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

2.常用属性

textSize 文字大小 单位sp(这个为啥用sp,dp/sp有啥区别还不知道,等着后续学到的时候我再单独写一篇文章)

textColor 文字颜色

lineSpacingMultiplier 几倍行距

lineSpacingExtra 直接设置行距的具体值

textIsSelectable 文字是否可复制

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textColor="#FF0000"
        android:lineSpacingMultiplier="1.5"
        android:text="@string/test" />

3.文字省略

使用lines与ellipsize混合可实现超过两行的内容以省略号方式显示

lines 表示有几行

ellipsize 表示省略号的位置,不设置该属性则不显示省略号

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:lines="2"
        android:text="@string/test" />

 

4.文字链接

autoLink属性
    none 普通文本
    web 网络链接
    email 邮件
    phone 电话
    map 国内用不上吧?
    all 根据text内容自动识别
 
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:autoLink="web"
        android:text="baidu.com" />

点击后自动跳转到浏览器

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值