Inflating AppBarLayout with Toolbar + TabLayout

前端 未结 7 1127
隐瞒了意图╮
隐瞒了意图╮ 2021-01-30 23:21

I currently have a DrawerLayout in my main.xml. There\'s a Toolbar wrapped in an AppBarLayout, and then a simple LinearLayout to swap out fragments.

One of the fragment

7条回答
  •  甜味超标
    2021-01-30 23:35

    The Artem_lens approach worked for me with some modifications.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        ...
    
        mTabLayout = (TabLayout) inflater.inflate(
                R.layout.partial_tab_layout,
                container,
                false);
        mAppBarLayout = (AppBarLayout) getActivity().findViewById(R.id.app_bar);
        mAppBarLayout.addView(mTabLayout,
                new LinearLayoutCompat.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT));
    
        ...
    }
    

    And removing the view at onDestroyView()

    @Override
    public void onDestroyView() {
        mAppBarLayout.removeView(mTabLayout);
        super.onDestroyView();
    }
    

提交回复
热议问题