TextView控件的使用

android:textColor="文本颜色"
android:textSize="文本大小..sp"
android:background="背景颜色 || 图片地址"
android:text="文本内容"


//设置文本位置
android:gravity="center_vertical" //设置垂直居中
android:gravity="right" //设置居右
android:gravity="center_vertical|center_horizontal" //设置垂直水平居中(这个例子说明可以混合)


//设置链接
android:autoLink="all"     //设置自动识别链接所有
android:autoLink="phone"     //设置自动识别链接,phone为链接到电话簿
android:autoLink="email"     //设置自动识别链接,phone为链接到邮箱
android:autoLink="web"     //设置自动识别链接,phone为链接到web网址


//设置图片摆放位置,其中图片所在的位置是app->res->drawable->apple.png
android:drawableLeft="@drawable/apple"   
android:drawableRight="@drawable/apple"
android:drawableTop="@drawable/apple"
android:drawableBottom="@drawable/apple"


//文本过长处理
android:ellipsize="start" 省略号在开头
android:ellipsize="middle" 省略号在中间
android:ellipsize="end" 省略号在结尾
android:ellipsize="marquee"设置跑马灯效果

//设置跑马灯效果
android:ellipsize="marquee"
android:focusable="true"          //设置可以获得焦点(针对键盘)
android:focusableInTouchMode="true"    //设置可以获得焦点(针对触屏),不过要满足上一个是true
android:clickable="true"          //设置可以点击
android:singleLine="true"         //设置单行显示
android:marqueeRepeatLimit="marquee_forever"  //设置时间永远


//设置阴影
//shadowDX、shadowDy、shadowRadius,说明分别是阴影的横、纵坐标偏移,以及阴影的半径
android:shadowColor="#45b97c"
android:shadowRadius="3.0"

//设置字形
android:textStyle="bold|italic"


通过下面程序可以大致浏览以上功能

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <!-- 显示超链接-->
    <TextView
        android:id="@+id/textView0"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#FF0000"
        android:textSize="18sp"
        android:background="#FFFFFF"
        android:text="拨打手机:13888888888"
        android:gravity="center_vertical"
        android:autoLink="phone"
        android:drawableLeft="@drawable/apple"/>
    <TextView
        android:id="@+id/textView1"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:textColor="#FF0000"
        android:textSize="18dip"
        android:background="#00FF00"
        android:text="Google搜索:http://www.google.com.hk"
        android:gravity="center_vertical|center_horizontal"
        android:autoLink="web" />
    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#FF0000"
        android:textSize="18sp"
        android:background="#FFFF00"
        android:text="发送邮件:[email protected]"
        android:gravity="center_vertical|center_horizontal"
        android:autoLink="email" />

    <!-- 设置文字的滚屏跑马灯效果 -->
    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:clickable="true"
        android:singleLine="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:text="文字滚屏文字跑马灯效果 --->加长加长加长 --->从头再来 -->"
        android:textSize="18sp"
        android:background="#FF0000"
        android:textColor="@android:color/white"/>

    <!-- 设置字符阴影-->
    <TextView
        android:id="@+id/TextView4"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:textSize="18sp"
        android:background="#69541b"
        android:textColor="#FFFFFF"
        android:text="设置字符串阴影颜色为绿色"
        android:shadowColor="#45b97c"
        android:shadowRadius="3.0"
        android:gravity="center_vertical|center_horizontal"
        android:singleLine="true"/>

    <!-- 设置字符的外形 -->
    <TextView
        android:id="@+id/txtTest"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="18sp"
        android:background="#FFFFFF"
        android:textColor="#FF0000"
        android:text="设置文字外形为italic"
        android:textStyle="bold|italic"
        android:gravity="center_vertical|center_horizontal" />
</LinearLayout>

运行结果如下:

工程资源源码:https://download.csdn.net/download/qq_38367681/10768693

猜你喜欢

转载自blog.csdn.net/qq_38367681/article/details/83109404