2

I am developing an android app. In the app there is one webview which fetches data from the internet and show it to the user. But actionbar is consuming some screen space. What i want to do is hide the actionbar while user scroll down in the webview. I have searched everywhere on the internet but could not find a proper way to do this. I am using appcompat actionbar and my min sdk is 10.

Faiyaz
  • 574
  • 1
  • 9
  • 39

2 Answers2

2

You can use ActionBar with Overlay Mode. Enable it by calling requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); before setContentView(). And hide the ActionBar using getSupportActionBar().hide();

Now for Scrolling event for WebView you can follow this answer in SO

Edit:

For Hiding ActionBar

getSupportActionBar().hide();

For Showing

getSupportActionBar().show();
Chinmoy Debnath
  • 2,814
  • 16
  • 20
  • Thanks for your answer Chinmoy. But i don't want to overlay the actionbar. I just want to hide it when user scroll down and want it back when user scrolls up. – Faiyaz Jul 23 '15 at 11:49
  • You need to use overlay because whenever you call getActionBar().hide(); you will see a jump on your screen. To remove this problem you need to add actionbar as overlay. And for hiding action bar getActionBar().hide(); is the method and for showing getActionBar().show(); – Chinmoy Debnath Jul 23 '15 at 11:51
  • Okay thanks Chinmoy. I will implement this method and mark your answer as correct. Thanks again. – Faiyaz Jul 23 '15 at 11:54
  • before activity created not possible http://stackoverflow.com/questions/18526144/actionbarcompat-hide-actionbar-before-activity-is-created-bug – LOG_TAG Jul 29 '15 at 07:55
  • The link doesn't open. – TheOnlyAnil Oct 24 '17 at 12:00
1

You can also look into CoordinatorLayout which is part of the new android design support library and enables you to collapse and expand the actionbar on child scrolling events.

GSala
  • 946
  • 7
  • 15
  • Where can i find CoordinatorLayout? – Faiyaz Jul 23 '15 at 12:15
  • Here's an example: [link](https://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout) You also have to add the dependency in your gradle file: compile 'com.android.support:design:22.2.0' – GSala Jul 23 '15 at 12:25
  • Don't think web views are supported for CoordinatorLayouts yet. – nilsi Jul 26 '15 at 14:54
  • place the WebView inside NestedScrollView. it will work. And of course they are inside CoordinatorLayout – Tuss Jul 07 '16 at 02:32
  • Don't use NestedScrollView inside Webview, it causes height issues plus google also doesn't recommend to use it with webview. – Mustansir Sep 12 '16 at 09:21
  • CoordinatorLayout approach causes webview scroll issues. – diman Oct 03 '17 at 10:52