0

我有一个 Web 视图,其中显示了从硬编码字符串(大约 1500 个字符)加载的 HTML。在 HTML 验证器中测试的 HTML。html 很简单,包含 div 和 p 标签,而不是 javascript。仅在 Android 版本 4 上,我得到了一个带有滚动条的空白页面,在低于 4 的 Android 版本上它可以正常工作。不幸的是,我无法公开漏洞代码。

Android 4 WebView 有什么不同吗?

我的代码:

mWebView.setWebChromeClient(mWebChromeClient);
mWebView.setWebViewClient(mWebViewClient);
mWebView.addJavascriptInterface(new JavaScriptInterface(getActivity()),JavaScriptInterface.NAME);

if (CLEAR_CACHE_ON_LOAD) {
    mWebView.clearCache(true);
}

mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);

mWebView.loadDataWithBaseURL("fake://", htmlString, "text/html", "UTF-8", "fake://");
//OR -
mWebView.loadData(htmlBase64String, "text/html", "base64");

XML:

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/expandingView" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
            <WebView
                android:id="@+id/webview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fadingEdge="vertical"
                android:layerType="software"
                android:scrollbars="none" />

            <View
                android:id="@+id/webViewClickOverlay"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </FrameLayout>

        <LinearLayout
            android:id="@+id/more_about_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/color_white_grey_selector"
            android:gravity="center_vertical"
            android:padding="@dimen/padding_medium"
            android:visibility="gone" >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="@dimen/padding_medium"
                android:text="@string/more_about"
                android:textColor="@color/vocativ_purple"
                android:textSize="@dimen/text_size_medium"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/label_more_about"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ellipsize="end"
                android:lines="1"
                android:text="SECOND NIGHT OF BLA"
                android:textColor="@color/vocativ_pink"
                android:textSize="@dimen/text_size_medium"
                android:textStyle="bold" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawableRight="@drawable/ic_arrow_pink" />
        </LinearLayout>

        <include
            android:id="@+id/related_content_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            layout="@layout/widget_story_container" />
    </LinearLayout>

</ScrollView>
4

1 回答 1

1

需要将 android:layerType="software" 设置为 android:layerType="none"

看下一个链接

于 2013-04-08T12:15:19.070 回答