NickF
NickF

Reputation: 5737

Android 4 long html in webview

I have a web view in which I show HTML loaded from hardcoded string (about 1500 characters). The HTML tested in HTML validator. The html is simple contains div and p tags, not javascript. Only on Android versions 4 I got a blank page with scroll, on Android versions lower than 4 it's works fine. Unfortunately I cannot expose the hole code.

Is there any difference in Android 4 WebView ?

My code:

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");

The 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>

Upvotes: 0

Views: 908

Answers (1)

NickF
NickF

Reputation: 5737

Needed to set android:layerType="software" to android:layerType="none"

See the next link

Upvotes: 1

Related Questions