如何 显示富文本

作者: zhengLH | 来源:发表于2017-11-28 18:16 被阅读1次

    【假设】后台返回数据格式(H5样式) 如下, 改怎么解析呢?

    【答案】

    (法1)推荐使用Webview显示:

      【链接】blog.csdn.net/nzzl54/article/details/53117344

    (法2) textview显示富文本信息

     【链接】 www.cnblogs.com/xieping/p/4784525.html

    (  A )

    new Thread(new Runnable() {

    @Override

    public void run() {

    // drawable = Drawable.createFromStream(url.openStream(), "");  //获取网路图片imgGetter = new Html.ImageGetter() {

    public Drawable getDrawable(final String source) {

    Log.i("lee", source);

    final Drawable drawable;

    URL url;

    try {

    Bitmap bitmap = Glide.with(mContext).load(ApiConfig.BASE_URL + source.substring(1)).asBitmap().centerCrop().into(100, 100).get();

    drawable = new BitmapDrawable(bitmap);

    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable

    .getIntrinsicHeight());

    return drawable;

    // drawable = Drawable.createFromStream(url.openStream(), "");  //获取网路图片} catch (Exception e) {

    Log.i("lee", "大佬说这是异常" + e.getMessage());

    e.printStackTrace();

    return null;

    }

    }

    };

    }

    }).start();*/

    // CharSequence charsequence  =  Html.fromHtml(bean.getIntroduction(),imgGetter,null);

    (B)

    /* new Thread(new Runnable() {

    @Override

    public void run() {

    charsequence = Html.fromHtml(bean.getIntroduction(),new Html.ImageGetter(){

    @Override

    public Drawable getDrawable(String s) {

    Log.i("lee", "pic路径:"+ s);

    Bitmap bitmap = null;

    try {

    bitmap = Glide.with(mContext).load(ApiConfig.BASE_URL + s.substring(1)).asBitmap().centerCrop().into(100, 100).get();

    }catch (Exception e) {

    Log.i("lee", e.getMessage());

    e.printStackTrace();

    }

    Log.i("lee",  "是否存在:" +bitmap );

    drawable = new BitmapDrawable(bitmap);

    //下面这句话不可缺少drawable.setBounds(0,0,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());

    return drawable;

    }},null);

    }

    }).start();*/

    /*    mCurriculumIntro.setText(charsequence);

    mCurriculumIntro.setMovementMethod(LinkMovementMethod.getInstance());*/


    【第三方库】

      blog.csdn.net/qq_24823401/article/details/74932203

    相关文章

      网友评论

        本文标题:如何 显示富文本

        本文链接:https://www.haomeiwen.com/subject/kezsbxtx.html