zoukankan      html  css  js  c++  java
  • android的webview控件实现适配手机屏幕自适应高度加载html内容

    public void showWebViewContent(Context context, String content) {
      if (!TextUtils.isEmpty(content)) { Matcher matcher = Pattern.compile("<body[^>]*>([\s\S]*)<\/body>").matcher(content); if (matcher.find()) {//通过正则表达式找出body的内容,包括body标签。下面是head内容,适配手机宽度、图片大小、文字换行 String head = "<head>" + "<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> " + "<style>img{max- 100%; auto; height:auto;} body{word-break:break-all;}</style>" + "</head>"; content = "<html>" + head + matcher.group() + "</html>"; } } WebView webview = new WebView(context); webview.getSettings().setDefaultTextEncodingName("utf-8"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { webview.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); } else { webview.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); } webview.loadData(content, "text/html; charset=utf-8", "utf-8"); }
  • 相关阅读:
    IDEA 修改JavaWeb的访问路径
    坦克大战--Java类型 ---- (1)音乐播放
    codeforces 620C
    算法笔记之KMP算法
    算法笔记数组
    26. Remove Duplicates from Sorted Array
    哈夫曼树的证明
    Complete Binary Search Tree
    Root of AVL Tree
    .net framework环境
  • 原文地址:https://www.cnblogs.com/yongfengnice/p/10609614.html
Copyright © 2011-2022 走看看