Skip to content
Advertisement

How to implement hiding the toolbar when scrolling WebView?

I have an Activity with WebView and my own AppBarLayout. I want to implement hiding/showing the AppBarLayout with animation when scrolling the WebView, like in the Google Chrome app.

I tried different ways.

  • ObservableWebView, but it doesn’t work correctly, it doesn’t always show AppBar, especially if the page is short.

  • ConstraintLayout with animations. Something similar, but still not the same as in Google Chrome.

  • Coordinator layout. This is the best variant, I think. But it have some bugs.

I have wrote the code of layout like this:

JavaScript

In this case the page is not scrolling. I have tried many variants. If in the behavior I put clean webview (without swiperefresh, nestedscrolling etc) it’s work correctly, but if I lock and unlock the screen – WebView swells up and on the bottom of page appears white empty place. I have been trying to solve this problem for several days now, but it doesn’t work. Please help make a stable solution to this problem. Thank you very much.

I tried this method: How to Hide ActionBar/Toolbar While Scrolling Down in Webview but if I lock and unlock the screen – WebView swells up and on the bottom of page appears white empty place

Advertisement

Answer

I created WebView with this features and it works perfect:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement