Android action bar - dynamically remove the action bar

I want to use the action in two ways

  • A list of items that can be edited, new ones added, etc. is displayed here.
  • It displays a list of items to select one.

As the main logic of the Activity, it is necessary to display a list of elements that I would like to handle with these two cases in the same Activity. However, at 1. I want to show the action bar so that the user can move from there to wherever he wants. In case 2. I do not want any action screen to be displayed, all the user can do is select an item or click cancel / return.

What is the best way to achieve this. My first guess would be two topics that I asked dynamically, which of the two cases is required. But I wonder if there is a way to easily remove the action bar from the screen programmatically, which will save me from declaring two topics, etc. Any suggestion on how you deal with this requirement will be very helpful.

thanks

+7
source share
3 answers

How about this?

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

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

+12
source

Use this:

 getActionBar().hide(); 

Android documentation to hide the action method

+3
source

If you want to actually remove the action bar (not create it first), and not create it, and then just hide it right away, you can do this through themes or through code.

Via tags or stylized attributes :

Use one of the predefined system themes, for example, Theme.Holo.NoActionBar or its variants. This is the easiest way to do this.

If you want to define the use of attributes within your custom theme, you can 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.

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

 requestWindowFeature(Window.FEATURE_NO_TITLE); 
+2
source

All Articles