Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Webview is scrolling to the top when click on link

I have a Webview loading static html content in my app.

the problem is, when I click on a link or an embed content (tweet, youtube video), the webview is scrolling back to the top.

It looks like a JS problem as mentioned here

I tried to use a NestedScrollView or some tricks with params like

android:focusableInTouchMode="true"

in a LinearLayout parent but nothing works

here's my xml :

  <android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <WebView
      android:id="@+id/article_webview"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>
  </android.support.v4.widget.NestedScrollView>

it will be in a recycler view.

My question is :

is there a way to prevent this behavior in the webview settings or xml ?

Thanks !

like image 585
Paul Aigueperse Avatar asked Dec 05 '17 00:12

Paul Aigueperse


1 Answers

I've been having the same problem. My WebView was inside a RecyclerView too.

When I added android:descendantFocusability="blocksDescendants" on my RecyclerView, the problem does not happen for me anymore.

<androidx.recyclerview.widget.RecyclerView
  android:descendantFocusability="blocksDescendants"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"/>
like image 198
Ersen Osman Avatar answered Nov 01 '22 20:11

Ersen Osman