• TextView 支持 html 图片显示


    引用:http://woshao.com/article/697693b8b65e11e0a18f000c29fa3b3a/

    在TextView中显示HTML内容的方法如下所示:

    1 TextView description=(TextView)findViewById(R.id.description);

    2 description.setText(Html.fromHtml(item.getDescription()));

    如果HTML中有图片的话,显示出来的图片会被一个小框取代,那么怎么样才能看到图片呢?查看了一下API,

    android.text.Html还还有 另一个方法:

    Html.fromHtml(String source,ImageGetter imageGetter,TagHandler tagHandler)


    例:

    ImageGetter imgGetter = new Html.ImageGetter() {
    02         public Drawable getDrawable(String source) {
    03             Drawable drawable = null;
    04             Log.d("Image Path", source);
    05             URL url;
    06             try {
    07                 url = new URL(source);
    08                 drawable = Drawable.createFromStream(url.openStream(),"");
    09             catch (Exception e) {
    10                 return null;
    11             }
    12             drawable.setBounds(00, drawable.getIntrinsicWidth(), drawable
    13                     .getIntrinsicHeight());
    14             return drawable;
    15         }
    16     };
    17 .........
    18 TextView description=(TextView)findViewById(R.id.description);
    19 description.setText(Html.fromHtml(item.getDescription(),imgGetter,null));
  • 相关阅读:
    NEO发行资产Token
    OSCP考试回顾
    Windows降权
    Mimikatz.ps1本地执行
    MS16-032提权正确方法
    一种通过HTTP传文件出网的姿势
    mac chromedriver error
    关于websocket 在生产环境中遇到的问题 及 解决办法
    how to install protobuff python
    Git 使用疑问
  • 原文地址:https://www.cnblogs.com/sode/p/2172020.html
Copyright © 2020-2023  润新知