Display HTML files in Android with Html.fromhtml (...) The returned value of the processed return value can be a parameter of SetText (). only HTML with text can handle HTML files in the following ways.
public static spanned fromhtml (String source)
to display HTML with pictures, use the following method to process the HTML file.
public static spanned fromhtml (String source, Html.imagegetter Imagegetter, Html.taghandler Taghandler)
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:14PX; Text-indent:2em; Background-color:rgb (255, 255, 255); " >imagegetter to process the processor in HTML, generate the Drawable object and return it. </span>
Creating Imagegetter primarily implements the following method, source is the value of the SRC attribute in the tag.
The following example displays HTML in TextView and EditView and inserts a picture.
Only HTML text is displayed, and clicking the button adds a picture after the TextView and EditView text.
Code:
Package Com.example.test;import Android.app.activity;import Android.graphics.drawable.drawable;import Android.os.bundle;import Android.text.html;import Android.text.html.imagegetter;import Android.view.View;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.edittext;import Android.widget.textview;public class Mainactivity extends activity {/** Called when the activity is first created. */t Extview TV; EditText et; Button Addpic; String CT; @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); et= (EditText) This.findviewbyid (R.ID.EDITTEXT1); tv= (TextView) This.findviewbyid (r.id.tv); ct= "Aaa<font color=\" red\ ">aaa</font>"; Addpic= (Button) This.findviewbyid (r.id.addpic); Addpic.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated method Stubct+ = "
<linearlayout 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 " tools:context= "${relativepackage}.${activityclass}" android:orientation= "vertical" > < TextView android:id= "@+id/tv" android:layout_width= "match_parent" android:layout_height= "Wrap_ Content " /> <edittext android:id=" @+id/edittext1 " android:layout_width=" match_parent " android:layout_height=" wrap_content " /> <button android:id=" @+id/addpic " Android:layout_width= "Match_parent" android:layout_height= "wrap_content" /></linearlayout>
32Spannable use (Android display HTML with picture (emoticon development))