32Spannable use (Android display HTML with picture (emoticon development))

Source: Internet
Author: User

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))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.