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>
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With