Android开发之UI组件TextView

编程入门 行业动态 更新时间:2024-10-15 10:21:43

Android开发之UI<a href=https://www.elefans.com/category/jswz/34/1771375.html style=组件TextView"/>

Android开发之UI组件TextView

UI组件TextView

属性:android:autoLink

我们用一个实例来解释这个属性

首先在strings.xml里写出我们需要的字符串

<?xml version="1.0" encoding="utf-8"?>

<resources>

 

    <string name="app_name">TextViewTest</string>

    <string name="webUrl">百度:;/string>

    <string name="email">我的:296463139@qq</string>

    <string name="phoneNumber">电话号码:10086</string>

    <string name="autoSAll">百度: 我的:296463139@qq</string>

 

</resources>

然后在我们的main.xml里声明属性

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=""

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical" >

 

    <TextView

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:autoLink="web"

        android:text="@string/webUrl" />

 

    <TextView

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:autoLink="email"

        android:text="@string/email" />

 

    <TextView

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:autoLink="phone"

        android:text="@string/phoneNumber" />

 

    <TextView

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:autoLink="all"

        android:text="@string/autoSAll" />

 

    <TextView

        android:id="@+id/tvId"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content" />

 

</LinearLayout>

/Activity

package cn.class3g.activity;

 

import android.app.Activity;

import android.os.Bundle;

import android.text.Html;

import android.widget.TextView;

 

public class TextViewTestActivity extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.main);

 

       TextView tv = (TextView) this.findViewById(R.id.tvId);

       String htmlStr = "<font size='30' color='#00FF22'>我</font>爱<b>你</b>"

              + "<a href='baidu'>百度</a>";

       tv.setText(Html.fromHtml(htmlStr));

    }

}

注意:

android:autoLink=”email” :会出现unsupported action,可能是模拟器bug,须探究

 

另外使用Html.fromHtml时,超链接只具备外观,不能跳转

效果图:

更多推荐

Android开发之UI组件TextView

本文发布于:2024-02-06 17:15:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1750321.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组件   Android   UI   TextView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!