文本框TextView的学习笔记

本文详细介绍了Android中TextView的各种属性及其用法,并通过具体示例展示了如何使用这些属性来定制文本视图的表现形式,包括文本颜色、字体大小、链接转换等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

       TextView作用:在界面中显示文本。直接继承View,它还是EditText、Button两个UI组件类的父类,并且还派生了CheckedTextView。

       示例:不同颜色、字体、带连接的文本

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	>

<!-- 建立一个文本框:
     drawableEnd:将文本框内文字的结尾处绘制指定图像
  -->	
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="我爱 Java"
    android:textSize="20pt"
    android:drawableEnd="@drawable/ic_launcher"      
    />

<!-- 建立一个文本框:
     android:singleLine:是否单行显示
     android:ellipsize:在文本中间截断,并显示省略号
     android:textAllCaps:是否将文本框中文字显示为大写字母
  -->
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:text="我爱java我爱java我爱java我爱java我爱java我爱java"
    android:ellipsize="middle"
    android:textAllCaps="true"
    />

<!-- 建立一个文本框:
     android:autoLink:是否将指定文本转为可单击的超级链接
  -->
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:text="邮件是ceshi110@110.com,电话是11223344"
    android:autoLink="email|phone"
    />

<!-- 建立一个文本框:
     android:shadowColor:设置文本框内文字的阴影颜色
     android:shadowDx:将文本框内文字的阴影在水平方向偏移
     android:shadowDy:将文本框内文字的阴影在垂直方向偏移
     android:shadowRadius:设置阴影的模糊程度,越大越模糊
  -->
<TextView
    android:layout_width="fill_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="#f00"
    android:textSize="18pt"
    />

<!-- 建立一个文本框:
     android:password:设置该文本框为一个密码框
  -->
<TextView
    android:id="@+id/passwd"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    android:password="true"
    />

<!-- 建立一个文本框:
     android:checkMark:设置该可勾选文本框的勾选图标
  -->
<CheckedTextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="可勾选的文本"
    android:checkMark="@drawable/ok"
    />
    
</LinearLayout>

显示效果:


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值