WebView 文本大小

2023-12-26

有时,当我加载页面(没有静态内容,动态构建)时,我看到字体太小1 http://s8.postimage.org/7akrcd8wl/webview1.png。如果我重新加载,我会正确看到它2 http://s7.postimage.org/cp6imu1dn/webview2.png。我来来回回地看了一下。然后……小。不是特定的页面,也不是特定的时间。甚至没有特定版本:我在 ICS 设备上部署,没问题,然后更改某些内容(例如字体大小),这就是问题。在 8 和 10 个模拟器上部署也是如此。

我的观点非常简单:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical" >
    <WebView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webviewArticle"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:padding="12dp" >
    </WebView>
</LinearLayout>

HTML构造(内容参数为格式化html)

String toShow = new StringBuffer()
    .append("<html>")
    .append("<head>")
    .append("<style type='text/css'>body{ font-size: large; color: #FFFFFF; background-color: #000000;}</style>")
    .append("</head>")
    .append(String.format(
        "<body><h1>%s</h1><div><img src='%s' alt='%s' style='width:100%%; height:auto' /></div><div style='background-color:#000000;'>%s</div><div><h3>%s</h3></div></body>",
        article.getTitle(),
        article.getImageLink().toString(),
        article.getTitle(),
        article.getContent().replace("%", "%25"), //html
        article.getAuthor()))
    .append("</html>")
    .toString();

mBrowser.getSettings().setBuiltInZoomControls(true);
mBrowser.setInitialScale(1);
CompatibilityUtils.setLoadWithOverviewMode(mBrowser, true); //set based on android version
mBrowser.getSettings().setUseWideViewPort(true);
mBrowser.loadDataWithBaseURL("fake://in/order/to/refresh", toShow, "text/html", "utf-8",null);

有什么提示吗?

附加说明 12/09/25:如图像所示,WebView 认为可用空间是屏幕的一半,并相应地放置文本。这很奇怪。最奇怪的是,它对文本(图像上方的标题和下方的 div)而不是图像如此认为!


WebSettings settings= webView.getSettings();

this

settings.setTextSize(WebSettings.TextSize.SMALLEST);

or

settings.setDefaultFontSize(10);//Larger number means larger font size
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

WebView 文本大小 的相关文章

随机推荐