Android基础UI组件(一):TextView文本框

简介

在Android的UI中,文本框用TextView组件表示,用于在界面上显示文字信息。TextView组件不仅能显示单行文本,也能显示多行文本,甚至可以显示带图像的文本。

TextView常用属性

 

android:autoLink设置当文本为URL链接,email,电话号码时是否显示为可单击的链接。可选值:none,web,email,phone,map,all
android:drawableButtom在文字下方放置图片。还有类似的左方,上方,右方
android:gravity设置文本位置,如center居中
android:hintText为空时的提示信息
android:maxLength文本最大长度,超过部分不显示
android:lines

设置文本的行数

android:singleLine设置单行显示,超过的用“.....”表示
android:textColor设置文本颜色
android:textSize设置文本字体大小
android:textStyle设置字形。可选值:bold(粗体)0,italic(斜体)1,bolditalic(粗斜)2,多个值用"|"隔开
android:typeface设置文本字体:normal0,sans1,serif2,monospace3
android:height文本域高度
android:width文本域宽度

实战

  • 创建一个空activity的项目
  • 在xml布局文件修改布局样式,改为LinearLayout线性布局,然后添加textView控件
  • 在activity类中根据ID获取控件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


<!--    <TextView-->
<!--        android:layout_width="wrap_content"-->
<!--        android:layout_height="wrap_content"-->
<!--        android:id="@+id/text1"-->
<!--        android:text="欢迎进入后台管理系统!"-->
<!--        android:height="100dp"-->
<!--        android:textSize="50dp"-->
<!--        android:textColor="#F00"-->
<!--        android:gravity="center"-->
<!--        ></TextView>-->

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@id/text2"
        android:text="www.baidu.com"
        android:autoLink="all"
        android:height="100dp"
        android:textSize="50dp"
        android:gravity="center"
        ></TextView>

</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/text1"
        android:text="欢迎进入后台管理系统!"
        android:height="100dp"
        android:textSize="50dp"
        android:textColor="#F00"
        android:gravity="center"
        ></TextView>

<!--    <TextView-->
<!--        android:layout_width="match_parent"-->
<!--        android:layout_height="wrap_content"-->
<!--        android:id="@id/text2"-->
<!--        android:text="www.baidu.com"-->
<!--        android:autoLink="all"-->
<!--        android:height="100dp"-->
<!--        android:textSize="50dp"-->
<!--        android:gravity="center"-->
<!--        ></TextView>-->

</LinearLayout>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值