1

The action bar can be shown even on pre-honeycomb devices, as shown via the actionbar-compat sample.

I want to be able to hide and show the action bar on demand (programmatically). How do I do that?

The problem is that getting the action bar using the support library returns null. I've also tried to find it using its id and set the visibility to gone, but it just showed a white space instead.

PhilMY
  • 2,621
  • 21
  • 29
android developer
  • 114,585
  • 152
  • 739
  • 1,270

3 Answers3

1

ok , i have a workaround , but it doesn't work for the beginning , meaning that for a very short time , the actionbar will be shown on the beginning.

here's the code i've created to hide the action bar (for pre-honeycomb versions) ,which i've thought of by looking at this post :

ViewGroup decorView = (ViewGroup) this.getWindow().getDecorView();
ViewGroup root = (ViewGroup) decorView.getChildAt(0);
View titleContainer = root.getChildAt(0);
titleContainer.setVisibility(View.GONE);

if anyone knows how to make the action bar hidden on the beginning and choose when to show it , please let me know.

EDIT: btw, if anyone wishes to use a theme via the manifest and uses actionBarSherlock, you could use either "Theme.Sherlock.Light.NoActionBar" or "Theme.Sherlock.NoActionBar" , and if you wish to hide&show in code, simply use getSupportActionBar().hide() and getSupportActionBar().show().

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270
1

in the end i've used actionBarSherlock.

it has much more features and this requested feature is one of them. maybe the new support library works with this feature , but i've already moved to this solution.

android developer
  • 114,585
  • 152
  • 739
  • 1,270
0

Try this,hide action bar in xml by setting following property in xml for your activity. `

<activity
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

Hope it helps if not then add a comment and if anything is wrong with my answer please correct me.

JCoder
  • 51
  • 9
  • this is wrong, as it hides the notification bar too. you need to create a theme in order to avoid this. – android developer Dec 19 '13 at 06:25
  • hmm .. yeah i noticed it hides the notification bar , i ll use your way.Thanks for correction. – JCoder Dec 19 '13 at 07:06
  • also the question was about doing it programmatically. anyway, i've updated my answer to have a solution for the manifest, even though it's not programmatically at all... – android developer Dec 19 '13 at 08:52