0

I have an HomeAcivity with 4 fragments. 3 of the fragments have no Toolbar of their own and I am showing the Activity's Toolbar in them. However, the 4th Fragment have Toolbar of its own.

Currently I am seeing 2 Toolbars in 4th Fragment, one its own and other that of Activity.How can I hide the Activity's Toolbar and just show its own Toolbar?

Please note that I don't want to update the content of Activity's Toolbar instead of showing new Toolbar inside Fragment. I want to show Fragments own Toolbar and hide that of Activity.

Please help me out.

Nitesh Kumar
  • 5,370
  • 5
  • 37
  • 54
  • Use this..http://stackoverflow.com/questions/2591036/how-to-hide-the-title-bar-for-an-activity-in-xml-with-existing-custom-theme – Nik Jan 16 '16 at 17:47
  • What's exactly the difference between your Activity's and your Fragment's Toolbar? Do you use AppCompatActivity and support Fragment? – Maxr1998 Jan 16 '16 at 17:54

1 Answers1

0

You can hide activity's toolbar from your 4th fragment

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_view, container, false);

    ((ToolbarView)getActivity().findViewById(R.id.toolbarView)).setVisibility(View.GONE);

    return rootView;
}

and show activity's toolbar from other three fragments

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_view, container, false);

    ((ToolbarView)getActivity().findViewById(R.id.toolbarView)).setVisibility(View.VISIBLE);

    return rootView;
}
puff
  • 11
  • 1