dorjeduck
dorjeduck

Reputation: 7794

android actionbar - removing the actionbar dynamically

I want to use an activity in two manners

  1. It shows a list of items which can be edited, new ones added etc
  2. It shows the list of items in order to choose one.

As the main logic of the Activity is to display the list of items I would like to handle these two cases in the same Activity. Nevertheless in the 1. I want to show the actionbar so that the user can navigate from there to wherever wanted. In the 2. case I dont want any actionbar to be shown, all the user can do is choose an item or press cancel/back.

What is the best way to achieve this. My first guess would be two themes which I set dynamically what of the two cases is required. But I wonder if there is also a way to easily remove the actionbar from the screen programmatically which would save me from declaring two themes etc. Any suggestion how you handle this requirement would be very helpful.

Thanks

Upvotes: 7

Views: 6387

Answers (4)

Joseph Ali
Joseph Ali

Reputation: 355

For those who have problems with getActionBar().hide();

consider using:

getSupportActionBar().hide();

Upvotes: 0

numan salati
numan salati

Reputation: 19494

If you want to actually remove the action bar (not create it in the first place) as opposed to create it but then just hiding it right away, you can do it via themes or via code.

Via theme or styled attributes:

Use one of the predefine system themes like Theme.Holo.NoActionBar or its variants. This is the easiest way to do it.

If you want to define using attributes inside your custom theme, then you could do this:

<resources>
    <style name="MyTheme" parent="some_parent_theme">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
    </style>
</resources>

Now add this theme to your activity or application.

Via code (make sure you call this before setContentView in Activity.onCreate):

requestWindowFeature(Window.FEATURE_NO_TITLE); 

Upvotes: 2

Nospherus
Nospherus

Reputation: 186

How about this?

public void hideActionBar(){
    getActionBar().hide();
}

Source: http://developer.android.com/guide/topics/ui/actionbar.html

Upvotes: 12

Artem Zinnatullin
Artem Zinnatullin

Reputation: 4447

Use this:

getActionBar().hide();

Android documentation for action bar hide method

Upvotes: 3

Related Questions