Android開發(fā)實(shí)現(xiàn)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ì)有所幫助。
- Android實(shí)現(xiàn)在TextView文字過長時(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文本過長滾動(dòng)顯示實(shí)現(xiàn)方法分析
相關(guān)文章
Android使用觀察者模式Observer實(shí)現(xiàn)網(wǎng)絡(luò)狀態(tài)監(jiān)聽
這篇文章主要為大家詳細(xì)介紹了Android使用觀察者模式Observer實(shí)現(xiàn)網(wǎng)絡(luò)狀態(tài)監(jiān)聽,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05Android可自定義垂直循環(huán)滾動(dòng)布局
這篇文章主要為大家詳細(xì)介紹了Android可自定義垂直循環(huán)滾動(dòng)布局,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03Android基于opencv實(shí)現(xiàn)多通道分離與合并
針對圖像多通道的分離與混合,OpenCV 4中提供了split()函數(shù)和merge()函數(shù)用于解決這些需求。本文講解一下Android如何調(diào)用這些函數(shù)實(shí)現(xiàn)多通道分離與合并2021-06-06Android實(shí)現(xiàn)果凍滑動(dòng)效果的控件
這篇文章給大家主要介紹了利用Android如何實(shí)現(xiàn)果凍效果滑動(dòng)效果的控件,實(shí)現(xiàn)的效果類似于iOS有阻尼效果的滑動(dòng)控件,一般我們比較親切地稱之為果凍控件,常見的如微信里[我]的那個(gè)面板模塊,即使沒有再多的選項(xiàng),也不會(huì)很生硬的不允許用戶滑動(dòng)。下面來一起看看吧。2016-11-11Android多點(diǎn)觸控技術(shù)實(shí)戰(zhàn) 針對圖片自由縮放和移動(dòng)
這篇文章主要為大家詳細(xì)介紹了Android多點(diǎn)觸控技術(shù)實(shí)戰(zhàn),自由地對圖片進(jìn)行縮放和移動(dòng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10Flutter實(shí)現(xiàn)仿微信分享功能的示例代碼
Flutter 用來快速開發(fā) Android iOS平臺應(yīng)用,在Flutter 中,通過 fluwx或者fluwx_no_pay 插件可以實(shí)現(xiàn)微信分享功能,本文將具體介紹實(shí)現(xiàn)的示例代碼,需要的可以參考一下2022-01-01