How to hide action bar for fragment?

前端 未结 9 1201
挽巷
挽巷 2021-01-31 08:17

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 a

9条回答
  •  佛祖请我去吃肉
    2021-01-31 08:49

    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.

提交回复
热议问题