重写Imagegetter
ublic class URLImageParser implements Html.ImageGetter { Context c; EditText container; private LoadingDialog mLoaddingDialog; /*** * 构建URLImageParser将运行AsyncTask,刷新容器 * * @param t * @param c */ public URLImageParser(EditText t, Context c) { this.c = c; this.container = t; mLoaddingDialog = new LoadingDialog((Activity) c); mLoaddingDialog.show(); } public Drawable getDrawable(String source) { URLDrawable urlDrawable = new URLDrawable(); // 获得实际的源 ImageGetterAsyncTask asyncTask = new ImageGetterAsyncTask(urlDrawable); asyncTask.execute(source); //返回引用URLDrawable我将改变从src与实际图像标记 return urlDrawable; } public class ImageGetterAsyncTask extends AsyncTask<String, Void, Drawable> { URLDrawable urlDrawable; public ImageGetterAsyncTask(URLDrawable d) { this.urlDrawable = d; } @Override protected Drawable doInBackground(String... params) { String source = params[0]; return fetchDrawable(source); } @Override protected void onPostExecute(Drawable result) { // 设置正确的绑定依据HTTP调用的结果 LogUtils.debug("图片下载完成"); mLoaddingDialog.dismiss(); LogUtils.debug("height=" + result.getIntrinsicHeight()); LogUtils.debug("width=" + result.getIntrinsicWidth()); urlDrawable.setBounds(0, 0, 0 + result.getIntrinsicWidth(), 0 + result.getIntrinsicHeight()); // 改变当前可提取的參考结果从HTTP调用 urlDrawable.drawable = result; // 绘制图像容器 URLImageParser.this.container.invalidate(); // For ICS URLImageParser.this.container.setHeight((URLImageParser.this.container.getHeight() + result.getIntrinsicHeight())); // Pre ICS URLImageParser.this.container.setEllipsize(null); } /*** * 得到Drawable的URL * * @param urlString * @return */ public Drawable fetchDrawable(String urlString) { try { InputStream is = fetch(urlString); Drawable drawable = Drawable.createFromStream(is, "src"); drawable.setBounds(0, 0, 0 + drawable.getIntrinsicWidth(), 0 + drawable.getIntrinsicHeight()); return drawable; } catch (Exception e) { return null; } } private InputStream fetch(String urlString) throws MalformedURLException, IOException { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(urlString); HttpResponse response = httpClient.execute(request); return response.getEntity().getContent(); } }
public class URLDrawable extends BitmapDrawable { // the drawable that you need to set, you could set the initial drawing // with the loading image if you need to protected Drawable drawable; @Override public void draw(Canvas canvas) { // override the draw to facilitate refresh function later if (drawable != null) { drawable.draw(canvas); } } }
从EditText里面getText的时候,注意这一点就可以了
String html = Html.toHtml(et_edit_tigan.getText());