最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)實(shí)現(xiàn)TextView顯示豐富的文本

 更新時(shí)間:2015年12月25日 12:36:42   作者:sgx425021234  
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)TextView顯示豐富的文本,涉及Android中TextView的使用技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開發(fā)實(shí)現(xiàn)TextView顯示豐富的文本的方法。分享給大家供大家參考,具體如下:

如圖,顯示html的元素控件,點(diǎn)擊連接實(shí)現(xiàn)上網(wǎng),發(fā)email,撥號

實(shí)現(xiàn)源碼如下:

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的標(biāo)志
    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());// 點(diǎn)擊的時(shí)候產(chǎn)生超鏈接
    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程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論

云安县| 公安县| 常宁市| 都江堰市| 来凤县| 伽师县| 绍兴县| 阜宁县| 凌海市| 鱼台县| 延安市| 房产| 通化市| 岫岩| 宁海县| 滦南县| 扎赉特旗| 宁国市| 嘉义市| 海淀区| 瓮安县| 揭西县| 安陆市| 上高县| 曲阜市| 若羌县| 望江县| 建昌县| 额济纳旗| 图片| 嵊泗县| 洞口县| 简阳市| 富蕴县| 汶上县| 重庆市| 扬中市| 全州县| 北流市| 水城县| 拉萨市|