Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue scrolling WebView in NestedScrollView Android 2.3 or less

I added Toolbar, Tablayout and Viewpager in my android app. There are three Tabs in TabLayout, each of which shows a WebView. I placed the WebView in a NestedScrollView to hide/show the Toolbar when the user scrolls down/up in the WebView. Toolbar is hiding in Android 3.0 or more. But unfortunately in Android 2.3 or less WebView does not scroll at first. I have to swipe to another Tab and when i come back to First Tab again WebView starts scrolling.

What i want?

I want that the WebView should scroll in Android 2.3 or less without any problem.

My WebView

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:isScrollContainer="false"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingTop="1dp">

     <WebView
         android:id="@+id/webviewtool"
         android:layout_width="match_parent"
         android:layout_height="fill_parent"
         android:numColumns="1"
         android:scrollbars="none"
         android:focusableInTouchMode="false"
         android:focusable="false"
         android:background="#FFFFFF" />

        </LinearLayout>
</android.support.v4.widget.NestedScrollView>
like image 879
Faiyaz Avatar asked Aug 26 '15 10:08

Faiyaz


1 Answers

Try to use this library: https://github.com/ksoichiro/Android-ObservableScrollView this one works from API 9+. But take in mind that 2.3 has a lot of issues with visuals, animations, etc

You can also download and check the code example of: "ActionBarControlWebViewActivity WebView & Action Bar" it's exactly what you are looking for. Link: ActionBar & WebView

Is as simple as use it like this:

ObservableWebView webView = (ObservableWebView) findViewById(R.id.web);
webView.setScrollViewCallbacks(this);
webView.loadUrl("file:///android_asset/lipsum.html");
like image 52
Mariano Zorrilla Avatar answered Oct 15 '22 17:10

Mariano Zorrilla