Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 445
dorjeduck Avatar asked Oct 14 '12 09:10

dorjeduck


3 Answers

How about this?

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

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

like image 53
Nospherus Avatar answered Nov 08 '22 19:11

Nospherus


Use this:

getActionBar().hide();

Android documentation for action bar hide method

like image 36
Artem Zinnatullin Avatar answered Nov 08 '22 19:11

Artem Zinnatullin


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); 
like image 25
numan salati Avatar answered Nov 08 '22 20:11

numan salati