Remove ActionBar in fragment

Viewed 7749

I have some troubles trying to remove a toolbar in a specific fragment, i have this code in onCreateView fragment method:

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_login,container,false);
    mValidator = new Validator(this);
    mValidator.setValidationListener(this);
    mFbHelper = new 
    mGHelper = new GoogleHelper(this, null, this);

    ((DrawerUtil) getActivity()).setDrawerLocked(true);
    ((AppCompatActivity) getActivity()).getSupportActionBar().hide();
    initViews(view);
    return view;
}

I can hide the ActionBar, but the idea is to remove the ActionBar to use properly a logo, im using this code: ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(state); but it doesnt work.enter image description here Any ideas?

7 Answers

For a specific fragment you can use :

override fun onStart() {
        super.onStart()
        (activity as AppCompatActivity).supportActionBar!!.hide()
    }

    override fun onStop() {
        super.onStop()
        (activity as AppCompatActivity).supportActionBar!!.show()
    }


    override fun onResume() {
        super.onResume()
        (activity as AppCompatActivity).supportActionBar!!.hide()
    }

for kotlin, using

import android.support.v7.app.AppCompatActivity

Try

 override fun onStart() {
        super.onStart()
        //hide action bar from splash screen
        (activity as AppCompatActivity).supportActionBar!!.hide()
 }

in the specific fragment(s, and

            supportActionBar!!.hide()

in the Activity/Activities.

Note: do not forget to replace "hide()" by "show()" when you want the ActionBar to be visible again.

Related