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.
Asked
Active
Viewed 2,507 times
2
-
Providing some code will help people assist you. – nomistic Jul 25 '15 at 16:36
-
@nomistic Solved my problem. – Faiyaz Jul 25 '15 at 16:39
2 Answers
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
-
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
-
-
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
-
-
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
-