How to get Toolbar from fragment?

后端 未结 10 1855
梦毁少年i
梦毁少年i 2020-11-28 01:45

I have ActionBarActivity with NavigationDrawer and use support_v7 Toolbar as ActionBar. In one of my fragments toolbar has custom view

10条回答
  •  半阙折子戏
    2020-11-28 02:39

    You have two choices to get Toolbar in fragment

    First one

    Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
    

    and second one

    Toolbar toolbar = ((MainActivity) getActivity()).mToolbar;
    

提交回复
热议问题