Android開發(fā)實(shí)現(xiàn)TextView顯示豐富的文本
本文實(shí)例講述了Android開發(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ì)有所幫助。
- Android實(shí)現(xiàn)在TextView文字過長(zhǎng)時(shí)省略部分或滾動(dòng)顯示的方法
- android實(shí)現(xiàn)上下滾動(dòng)的TextView
- android TextView不用ScrollViewe也可以滾動(dòng)的方法
- Android中TextView實(shí)現(xiàn)垂直滾動(dòng)和上下滾動(dòng)效果
- Android TextView實(shí)現(xiàn)垂直滾動(dòng)效果的方法
- Android編程實(shí)現(xiàn)TextView垂直自動(dòng)滾動(dòng)功能【附demo源碼下載】
- Android TextView 字體滾動(dòng)效果
- Android中TextView實(shí)現(xiàn)超過固定行數(shù)顯示“...展開全部”
- Android TextView顯示html樣式的文字
- Android實(shí)現(xiàn)TextView顯示HTML加圖片的方法
- Android DrawableTextView圖片文字居中顯示實(shí)例
- Android開發(fā)中TextView文本過長(zhǎng)滾動(dòng)顯示實(shí)現(xiàn)方法分析
相關(guān)文章
Android實(shí)現(xiàn)上傳文件到服務(wù)器實(shí)例詳解
本篇文章詳細(xì)介紹了Android實(shí)現(xiàn)上傳文件到服務(wù)器實(shí)例詳解,實(shí)現(xiàn)了文件每隔5秒進(jìn)行上傳,有需要的可以了解一下。2016-11-11
Android實(shí)現(xiàn)隨機(jī)圓形云標(biāo)簽效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)隨機(jī)圓形云標(biāo)簽效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
Android 拍照選擇圖片并上傳功能的實(shí)現(xiàn)思路(包含權(quán)限動(dòng)態(tài)獲取)
這篇文章主要介紹了Android 拍照(選擇圖片)并上傳(包含權(quán)限動(dòng)態(tài)獲取),本文分步驟給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12
Android中的SpannableString與SpannableStringBuilder詳解
這篇文章主要給大家介紹了關(guān)于Android中SpannableString與SpannableStringBuilder的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-10-10
android的RecyclerView實(shí)現(xiàn)拖拽排序和側(cè)滑刪除示例
在平時(shí)開發(fā)應(yīng)用的時(shí)候,經(jīng)常會(huì)遇到列表排序、滑動(dòng)刪除的需求。這篇文章主要介紹了android的RecyclerView實(shí)現(xiàn)拖拽排序和側(cè)滑刪除示例,有興趣的可以了解一下。2017-02-02

