国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android開發實現TextView顯示豐富的文本

2020-04-11 11:07:54
字體:
來源:轉載
供稿:網友

本文實例講述了Android開發實現TextView顯示豐富的文本的方法。分享給大家供大家參考,具體如下:

如圖,顯示html的元素控件,點擊連接實現上網,發email,撥號

實現源碼如下:

MainActivity.java

package com.example.textview2;import android.os.Bundle;import android.app.Activity;import android.text.Html;import android.text.method.LinkMovementMethod;import android.view.Menu;import android.widget.TextView;public class MainActivity extends Activity {  private TextView textView1, textView2;  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    textView1 = (TextView) this.findViewById(R.id.textview1);    textView2 = (TextView) this.findViewById(R.id.textview2);    // 添加一段html的標志    String html = "<font color='red'></font><br><br><br>";    html += "<font color='#0000ff'><big><i></i></big></font><p>";    html += "<big><a ;    CharSequence charSequence = Html.fromHtml(html);    textView1.setText(charSequence);    textView1.setMovementMethod(LinkMovementMethod.getInstance());// 點擊的時候產生超鏈接    String text = "我的URL:http://www.sina.com/n";    text += "我的email:abcd@126.com/n";    text += "我的電話:+ 86 010-89487389";    textView2.setText(text);    textView2.setMovementMethod(LinkMovementMethod.getInstance());  }  @Override  public boolean onCreateOptionsMenu(Menu menu) {    // Inflate the menu; this adds items to the action bar if it is present.    getMenuInflater().inflate(R.menu.main, menu);    return true;  }}

strings.xml

<?xml version="1.0" encoding="utf-8"?><resources>  <string name="action_settings">Settings</string>  <string name="hello_world">Hello world!</string>  <string name="app_name">如何顯示html的元素控件</string>  <color name="green">#00FF00</color>  <string name="link_text"><a href="tel:13693207964">打電話</a></string></resources>

activity_main.xml

<RelativeLayout 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"  android:paddingBottom="@dimen/activity_vertical_margin"  android:paddingLeft="@dimen/activity_horizontal_margin"  android:paddingRight="@dimen/activity_horizontal_margin"  android:paddingTop="@dimen/activity_vertical_margin"  tools:context=".MainActivity" >  <TextView android:layout_width="fill_parent"    android:layout_height="wrap_content" android:id="@+id/textview1"    android:padding="20sp" />  <TextView    android:id="@+id/textview2"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:autoLink="all"    android:padding="20sp"    android:text="@string/link_text"    android:textSize="20sp" /></RelativeLayout>

希望本文所述對大家Android程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嘉义市| 镇平县| 怀集县| 利津县| 申扎县| 扶风县| 伊宁市| 渝中区| 岳阳市| 清苑县| 谢通门县| 抚顺县| 博湖县| 霍山县| 乌兰察布市| 宽甸| 辽阳县| 重庆市| 安龙县| 牡丹江市| 南木林县| 和硕县| 桂平市| 崇左市| 金乡县| 庆城县| 民勤县| 昌宁县| 石棉县| 台州市| 天津市| 修文县| 金坛市| 襄汾县| 青神县| 平遥县| 化德县| 通道| 汕头市| 秭归县| 明水县|