android - 在android Webview中折叠html加载
问题描述
我有 Html 内容显示折叠窗口。但这不是在 Android WebView 部分中加载的。仅显示白屏。
我的 WebView 代码是
WebView webView = (WebView) rootView.findViewById(R.id.webview);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setJavaScriptEnabled(true);
// webView.getSettings().setBuiltInZoomControls(true);
// webView.setInitialScale(1);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setSupportMultipleWindows(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
title="<head><link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\">"+
"<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js\"></script>"+
"<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\"></script></head>";
title= title+"<div class=\"panel-group\" id=\"accordion\"><div class=\"panel panel-default\"><div class=\"panel-heading\"><h4 class=\"panel-title\">" +
"<a data-toggle=\"collapse\" data-parent=\"#accordion\" href=\"#collapseOne\">1. What is HTML?</a></h4></div><div id=\"collapseOne\" class=\"panel-collapse collapse in\"><div class=\"panel-body\">" +
"<p>HTML stands for HyperText Markup Language. HTML is the standard markup language for describing the structure of web pages. <a href=\"https://www.tutorialrepublic.com/html-tutorial/\" target=\"_blank\">Learn more.</a></p>" +
" </div></div></div></div>";
webView.loadData(title, "text/html;", "");
解决方案
您很可能遇到过视图层类型的问题。试试这个代码:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webSettings.setMixedContentMode(0);
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
并尝试在 Manifest 中设置硬件加速:
android:hardwareAccelerated="true"
推荐阅读
- python - 如何遍历不同的链接以在 pandas 中创建数据框?
- python-3.x - 如何读取 .dat 文件和 .hea 文件?
- javascript - 是否可以在 Javascript 中的 mouseenter 上暂停此动画?
- javascript - Electron 在浏览器中打开 url 并锁定或灰色显示 url,因此无法编辑
- unity3d - PBR着色器太透明
- python - average_clustering() 得到了一个意外的关键字参数“试验”
- apache-kafka - kafka-topics 在重启时被截断
- encryption - 如何解压/解压原始 grpc 数据?
- python - 从按钮命令调用的函数中的 Tkinter Toplevel() 使变量无法访问
- c - 为什么 getchar 正在读取另一个值?