欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

32Spannable的使用(Android顯示html帶圖片(表情開發(fā)) - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設(shè)-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設(shè)/小程序開發(fā)/軟件開發(fā)

知識(shí)

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們在追求其視覺表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營銷的便利,運(yùn)營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!

您當(dāng)前位置>首頁 » 新聞資訊 » 技術(shù)分享 >

32Spannable的使用(Android顯示html帶圖片(表情開發(fā))

發(fā)表時(shí)間:2020-11-6

發(fā)布人:葵宇科技

瀏覽次數(shù):73


Android中顯示html文件要用Html.fromHtml(...)處理過的返回值,返回值可以成為setText()的參數(shù)。只顯示帶文本的html可以用下面的方法處理html文件。
public static Spanned fromHtml (String source)  

顯示帶圖片的html要用下面的方法處理html文件。
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 為處理html中<img>的處理器,生成Drawable對象并返回。</span>

創(chuàng)建ImageGetter 主要實(shí)現(xiàn)下面的方法,source為<img>標(biāo)簽中src屬性的值。
public Drawable getDrawable(String source)  

下例為在TextView和EditView中顯示html,并插入圖片。
下圖只顯示html文字,點(diǎn)擊按鈕會(huì)在TextView和EditView文本后添加圖片。
[img]http://img.blog.csdn.net/20141231084749890?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hlbmZ1ZHVvX2xvdmVpdA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
代碼:
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. */
	TextView 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(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				ct+="<img src=http://www.sjsjw.com/""+R.drawable.ic_launcher+"/"/>";
				 refreshView();
			}
        	
        });
       
       refreshView();
        
        
    }
    private void refreshView(){
    	 et.setText(Html.fromHtml(ct,imageGetter,null));
         tv.setText(Html.fromHtml(ct,imageGetter,null));
    }
    ImageGetter imageGetter = new ImageGetter()  
    {  
        @Override  
        public Drawable getDrawable(String source)  
        {  
            int id = Integer.parseInt(source);  
            Drawable d = getResources().getDrawable(id);  
            d.setBounds(0, 0, d.getIntrinsicWidth(), d .getIntrinsicHeight());  
            return d;  
        }  
    };  
}

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

相關(guān)案例查看更多