[英]Display Css Styled Html Data on ListView in Android
So, I want to display big html string that includes css (font-size, color, font-family, text-decoration etc..) part by part on a ListView
.所以,我想在
ListView
上部分显示包含 css (字体大小、颜色、字体系列、文本装饰等)的大 html 字符串。 I know there are some options for this, like using WebView
and TextView
with fromHtml()
method, but fromHtml isn't supporting css and WebView isn't divisible for ListView items. I know there are some options for this, like using
WebView
and TextView
with fromHtml()
method, but fromHtml isn't supporting css and WebView isn't divisible for ListView items. Any idea for this?有什么想法吗?
TextView
very poor about css, but it isn't a tool showing a styled website content so it's enough for simple html texts. TextView
对 css 非常差,但它不是显示样式网站内容的工具,因此对于简单的 html 文本来说已经足够了。 When it comes to WebView
, it's a good idea for showing complex html, css, javascript contents.当涉及到
WebView
时,最好显示复杂的 html、css、ZDE9B9ED708D7E2E1ZEFFEE1 内容。 You can use if you need.如果需要,您可以使用。 Certainly it isn't faster then
TextView
, but there are some performance improvements, as follows:当然它并不比
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.