Android開發(fā)實現(xiàn)TextView顯示豐富的文本
本文實例講述了Android開發(fā)實現(xiàn)TextView顯示豐富的文本的方法。分享給大家供大家參考,具體如下:
如圖,顯示html的元素控件,點擊連接實現(xiàn)上網(wǎng),發(fā)email,撥號
實現(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());// 點擊的時候產(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è)計有所幫助。
- Android實現(xiàn)在TextView文字過長時省略部分或滾動顯示的方法
- android實現(xiàn)上下滾動的TextView
- android TextView不用ScrollViewe也可以滾動的方法
- Android中TextView實現(xiàn)垂直滾動和上下滾動效果
- Android TextView實現(xiàn)垂直滾動效果的方法
- Android編程實現(xiàn)TextView垂直自動滾動功能【附demo源碼下載】
- Android TextView 字體滾動效果
- Android中TextView實現(xiàn)超過固定行數(shù)顯示“...展開全部”
- Android TextView顯示html樣式的文字
- Android實現(xiàn)TextView顯示HTML加圖片的方法
- Android DrawableTextView圖片文字居中顯示實例
- Android開發(fā)中TextView文本過長滾動顯示實現(xiàn)方法分析
相關(guān)文章
Android使用觀察者模式Observer實現(xiàn)網(wǎng)絡(luò)狀態(tài)監(jiān)聽
這篇文章主要為大家詳細介紹了Android使用觀察者模式Observer實現(xiàn)網(wǎng)絡(luò)狀態(tài)監(jiān)聽,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05Android基于opencv實現(xiàn)多通道分離與合并
針對圖像多通道的分離與混合,OpenCV 4中提供了split()函數(shù)和merge()函數(shù)用于解決這些需求。本文講解一下Android如何調(diào)用這些函數(shù)實現(xiàn)多通道分離與合并2021-06-06Android多點觸控技術(shù)實戰(zhàn) 針對圖片自由縮放和移動
這篇文章主要為大家詳細介紹了Android多點觸控技術(shù)實戰(zhàn),自由地對圖片進行縮放和移動,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-10-10