How to hide action bar for fragment?

android, android-actionbar

Solution

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.

Problem

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

Original source

Related problems