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
Put
getSupportActionBar().hide()
beforesetContentView
in the Activity that holds the fragments.Also add this:
((AppCompatActivity) getActivity()).getSupportActionBar().hide()
in the fragments before inflating layout. This works if you are using thisActionBarActivity
.It also removes my lags in hiding action barHide actionBar using this in the required fragment.
And Show actionBar with this in your next fragment.
This solution is for complex non-AppCompat applications that use native ToolBar when running Lollipop onwards and native ActionBar otherwise.
It assumes you want to hide the ActionBar whenever Fragments are visible.
Inside onCreate() in each of your Activities:
OR (much better) inside a 'singleton' class that implements Application.ActivityLifecycleCallbacks
Inside the utility class:
Using onActivityCreated() is a solution that requires no changes to your Fragments or Activities!
Have you tried
getActivity().getSupportActionBar().hide()
in theonCreate()
of the fragment you wish the ActionBar to be hidden in?I am assuming you are not using
ActionBarSherlock
.You can simply put this into your Fragment Class createView method:-
getActionBar().hide()
orgetSupportActionBar().hide()
(if using ActionBarCompat v7 lib). Regards