1

I have a html file in WebView and it only contains text. It's not scrolling API 30 device(emulator). But it's scrolling other devices below api 30.

xml:

<WebView
        android:id="@+id/web_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" i tried match_parent and 0dp
        app:layout_constrainedHeight="true"
        android:layout_marginStart="@dimen/_20sdp"
        android:layout_marginTop="@dimen/_20sdp"
        android:layout_marginEnd="@dimen/_20sdp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/divider" />

I also tried:

           android:scrollbars="vertical" (xml)
           webView.isVerticalScrollBarEnabled = true (programatic)

and tried yo use FrameLayout or ScrollView but still it didn't work. By the way I load an asset file:

           webView.loadUrl("file:///android_asset/Agreement.html")

And this is example structure of html file:

    <html>
    <head>
    <title>Agreement</title>
    </head>
    <body>
    <p>some texts... with <i> tag sometimes.... there are 2 paragraph </p>
    </html>
Mehmet Gür
  • 503
  • 7
  • 20

1 Answers1

0

The issue is related to the default behavior changes of WebView scrolling API 30.

The API 30 WebView is handled by ScrollView Parent. If it doesn't exist it is handled by WebView.


You have to disable the WebView scroll:

webView.setScrollbarFadingEnabled(false);

Wrap WebView inside ScrollView and set the height match_parent:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <WebView
        android:id="@+id/web_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</ScrollView>

Add the following attribute to the WebView in the .xml layout if you're using ConstraintLayout:

<WebView
    android:id="@+id/web_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constrainedHeight="true" />

Add the android:scrollbars and android:scrollbarStyle attributes to WebView in your .xml layout:

<WebView
    android:id="@+id/web_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:scrollbarStyle="insideOverlay" />

Check if the content from inside WebView exceeds the height screen.


Use a different layout like LinearLayout or RelativeLayout that may resolve the issue:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <WebView
        android:id="@+id/web_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scrollbars="vertical" />

</LinearLayout>

Verify the custom styles applied to WebView that can conflict:

  1. Open styles.xml in res/values directory.
  2. Check custom styles. (They could have a parent Widget.WebView)
  3. Check if custom styles conflicts or if they set the height or width.
  4. Remove or modify to see if it resolves the scroll.