There is an Activity with the following code:

  public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); FragmentManager manager = getFragmentManager(); FragmentTransaction ft = manager.beginTransaction(); ft.replace(R.id.leftcontent, new Requests()); ft.commit(); toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { toolbar.bringToFront(); setSupportActionBar(toolbar); } } 

When loading a new fragment, I tried to disable the toolbar in the following way:

 getActivity.getActionBar.hide 

but the error takes off. Tell me how to do it right?

  • one
    getActivity().getActionBar().hide() ? - pavlofff

2 answers 2

since you use setSupportActionBar() , then you need to use a similar getter

((AppCompatActivivty)getActivity()).getSupportActionBar().hide()

  • and the fragment itself must also be from SupportLibrary or not? I just see toolBar on 1 fragment and not on the next fragment ... although by default it should be visible on all fragments, if initialized in activity? - Sergey
  • not necessary, but it is better not to mix in the application and try to use one thing - andreich
  • and access the toolbar elements as an actionbar? tvTitle = (TextView) getActivity (). getParent (). findViewById (R.id.tvTitle); - Sergey
  • I'd rather do this with toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar); and therefore already in the toolbar to search for them toolbar.findViewById(R.id.tvTitle) - andreich
  • thanks, it helped. - Sergey
 toolbar.setVisibility(View.GONE); //hide toolbar.setVisibility(View.VISIBLE); //show 

Or like this:

 getSupportActionBar().hide(); // for hiding getSupportActionBar().show(); // for show 

If you work in a fragment, then so:

 getActivity().getSupportActionBar().hide(); //To hide getActivity().getSupportActionBar().show(); //To Show 
  • Why is only getActionBar () available to me? getSupportActionBar () this method is not available .. - Sergey
  • @ Sergey and toolbar.setVisibility (View.GONE) does not help? - iFr0z