• android webview 全屏100%显示图片


    这里引用 第三方类库 

    implementation 'org.jsoup:jsoup:1.10.2'

    定义工具类 HtmlUtils
    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.nodes.Element;
    import org.jsoup.select.Elements;
    
     
    public class HtmlUtils {
        /**
         * 将html文本内容中包含img标签的图片,宽度变为屏幕宽度,高度根据宽度比例自适应
         **/
        public static String getNewContent(String htmltext){
            try {
                Document doc= Jsoup.parse(htmltext);
                Elements elements=doc.getElementsByTag("img");
                for (Element element : elements) {
                    element.attr("width","100%").attr("height","auto");
                }
    
                return doc.toString();
            } catch (Exception e) {
                return htmltext;
            }
        }
    }
    View Code

    使用方法

     if(!TextUtils.isEmpty(mCourseDetailRes.getVideo_intro())) {
                       mWebView.setVisibility(View.VISIBLE);
                       WebSettings webSettings = mWebView.getSettings();
                       // 启用JS
                       webSettings.setJavaScriptEnabled(true);
                       webSettings.setUseWideViewPort(true);
                       webSettings.setLoadWithOverviewMode(true);
                       webSettings.setBuiltInZoomControls(false);//开启zoom
                       webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
                       webSettings.setDisplayZoomControls(false);
                       mWebView.setWebViewClient(new WebViewClient());
                       String html=HtmlUtils.getNewContent(mCourseDetailRes.getVideo_intro());
                       mWebView.loadData(html+ "", "text/html", "UTF-8");
                   }
    View Code

     注意 webview loadData 显示中文乱码,加上charset=UTF-8


    mWebView.loadData(html + "", "text/html; charset=UTF-8", "UTF-8");
    字体放大功能
    webSettings.setTextZoom(220);//字体大小
  • 相关阅读:
    洛谷——P1141 01迷宫
    洛谷——P1781 宇宙总统
    洛谷——P1608 路径统计
    洛谷——P1144 最短路计数
    洛谷—— P1162 填涂颜色
    python(22)- 递归和函数式编程
    android驱动例子(LED灯控制)
    Android之SDK、NDK、JNI和so文件
    NDK 与 JNI 的关系
    Android之NDK开发
  • 原文地址:https://www.cnblogs.com/freexiaoyu/p/10979310.html
Copyright © 2020-2023  润新知