Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Hide ActionBar/Toolbar While Scrolling Down in Webview

Tags:

In Google chrome and play store. the app can hide the actionbar while scrolling and allows the user to Browse conveniently. Please Help me to do like this.

I've used onTouchListener for webview it doesn't works.

mWebView.setOnTouchListener(new View.OnTouchListener() {             @Override             public boolean onTouch(View v, MotionEvent event) {                 switch (event.getAction()) {                     case MotionEvent.ACTION_DOWN:                         getSupportActionBar().show();                             break;                     case MotionEvent.ACTION_UP:                         getSupportActionBar().hide();                             break;                     default: break;                 }                 return false;             }         }); 

Thanks in Advance

like image 419
Sathish Kumar Avatar asked Feb 27 '15 17:02

Sathish Kumar


People also ask

How do I hide support action bar?

Hide the Status Bar on Android 4. getDecorView(); // Hide the status bar. // status bar is hidden, so hide that too if necessary. ActionBar actionBar = getActionBar();

How do I disable scrolling in Webview?

setScrollContainer(false); Don't forget to add the webview. setOnTouchListener(...) code above to disable all scrolling in the webview.

What is the difference between toolbar and action bar in Android?

What is the difference between the toolbar and the action bar? The most obvious difference between the two is the updated visual design of the toolbar. The toolbar no longer includes an icon on the left side and decreases some of the spacing between the action items on the right side.


1 Answers

You can do this without any Java code using the design library's CoordinatorLayout and NestedScrollView, with app:layout_scrollFlags set on Toolbar. Here's how you do it.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent">  <android.support.design.widget.AppBarLayout     android:id="@+id/appbar"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">      <android.support.v7.widget.Toolbar         android:id="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="?attr/actionBarSize"         android:background="?attr/colorPrimary"         app:layout_scrollFlags="scroll|enterAlways"         app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> </android.support.design.widget.AppBarLayout>  <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_gravity="fill_vertical"    android:fillViewport="true"     app:layout_behavior="@string/appbar_scrolling_view_behavior">      <WebView         android:id="@+id/webview"         android:layout_width="match_parent"         android:layout_height="match_parent"/> </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout> 

You can play around with with different layout_scrollFlags and fitsSystemWindows behaviour once you get the hang of it.

like image 155
Dhir Pratap Avatar answered Oct 23 '22 00:10

Dhir Pratap