2 回答
TA贡献1946条经验 获得超4个赞
TextView
对 css 的了解很差,但它不是一个显示样式化网站内容的工具,因此对于简单的 html 文本来说已经足够了。当谈到 时WebView
,显示复杂的 html、css、javascript 内容是一个好主意。如果需要,您可以使用。当然它没有那么快TextView
,但是有一些性能改进,如下:
// In AndroidManifest
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
...
>
<activity android:name=".activity.MainActivity"
android:hardwareAccelerated="true">
...
// In onCreate method from Activity class
WebView webView = (WebView) findViewById(R.id.webViewId);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDefaultTextEncodingName("utf-8");
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(false);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
settings.setLoadWithOverviewMode(true);
settings.setDomStorageEnabled(true);
this.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
this.setScrollbarFadingEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
this.setLayerType(View.LAYER_TYPE_HARDWARE, null); // chromium, enable hardware acceleration
else
this.setLayerType(View.LAYER_TYPE_SOFTWARE, null); // older android version, disable hardware acceleration
// use this, for don't getting some errors.
webView.loadDataWithBaseURL(null, "HtmlString", "text/html; charset=UTF-8", "UTF-8", null);
- 2 回答
- 0 关注
- 99 浏览
添加回答
举报