How to hide action bar for fragment?

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.

Leave a Comment