zoukankan      html  css  js  c++  java
  • 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));
  • 相关阅读:
    左边菜单导航
    css3实现轮播
    js-统计选项个数
    空间评论。回复。点赞功能
    简单的购物车功能
    字符串常用的几种方法
    React,js实现分页的案列
    python2的cgi程序
    开发环境和工具
    github入门
  • 原文地址:https://www.cnblogs.com/sode/p/2172020.html
Copyright © 2011-2022 走看看