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

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

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

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

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

實(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>

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

赫章县| 乳山市| 涟水县| 增城市| 六安市| 房产| 正定县| 铜山县| 广南县| 依安县| 江阴市| 墨脱县| 稷山县| 诏安县| 城口县| 达尔| 邵阳县| 交城县| 抚州市| 平南县| 盖州市| 胶南市| 长葛市| 亚东县| 平凉市| 砀山县| 延吉市| 襄城县| 分宜县| 光泽县| 汤阴县| 成都市| 南岸区| 江川县| 红桥区| 永昌县| 德钦县| 司法| 天镇县| 台南市| 保定市|