Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide action bar for fragment?

How can I hide action bar for certain fragment? I have searched for the answer at stackoverflow, but I have only found a solution, which involves disabling action bar for main activity in android manifest. Since I need to disable action bar for one fragment, this is not an option. Any ideas? Thanks.

EDIT: min API level is 7, sherlock is not being used

like image 398
user3178137 Avatar asked Feb 01 '14 21:02

user3178137


People also ask

How do I hide action bars?

If you want to hide Action Bar throughout the app (Activities, Fragments) everywhere, you can simply navigate to res > values > styles.

How do we hide the menu on the toolbar in one fragment?

When you click the show button to open a fragment, you can see the fragment menu items ordered before activity menu items. This is because of the menu item's android:orderInCategory attribute value. When you click the hide button to hide the fragment. The fragment menu items disappear from the action bar also.

How can use no action bar in Android?

If you want to hide Action Bar from the entire application (from all Activities and fragments), then you can use this method. Just go to res -> values -> styles. xml and change the base application to “Theme.

Which method is used to hide the activity title?

The requestWindowFeature(Window. FEATURE_NO_TITLE) method of Activity must be called to hide the title.


1 Answers

If you are using AppCompatActivity (you should) then this is the solution that worked for me:

((AppCompatActivity) getActivity()).getSupportActionBar().hide(); 

You can add this in onCreate(). The support fragment's getActivity() returns a FragmentActivity, and this does not contain the getSupportActionBar() method. Using just getActionBar() gives null-pointer exception if you have AppCompatActivity.

like image 99
Gober Avatar answered Sep 29 '22 11:09

Gober