Show or hide ActionBar when scrolling webview

In my solution, I use Android-ObservableScrollView library. You can find this library at this link

  1. Add library to your project:
    compile 'com.github.ksoichiro:android-observablescrollview:1.6.0'
    
  2. Add ObservableScrollView to layout:
    <com.github.ksoichiro.android.observablescrollview.ObservableWebView
            android:id="@+id/news_detail_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    
  3. Add ObservableScrollViewCallbacks to activity:
    this.contentWebView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
                @Override
                public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
                }
    
                @Override
                public void onDownMotionEvent() {
                }
    
                @Override
                public void onUpOrCancelMotionEvent(ScrollState scrollState) {
                    if (scrollState == ScrollState.UP) {
                        // hide your action bar
                    } else if (scrollState == ScrollState.DOWN) {
                        // show your action bar
                    }
                }
            });
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s