TabLayout update tab content with a custom view

后端 未结 4 1043
悲&欢浪女
悲&欢浪女 2021-02-01 03:48

I\'m using TabLayout of the new material design and i have a problem, i can\'t update tab content of a custom view once the tab is created:

I can simplify m

4条回答
  •  醉梦人生
    2021-02-01 04:35

    Have a look the Answer you need to set the layout as expected by you. If you want to change the Tab Content then make changes in Tab.setOnTabSelectedListener()

    tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            if(tab.getPosition()==1){
                    tabLayout.setTabTextColors(ContextCompat.getColor(getActivity(), R.color.unselected_tab),ContextCompat.getColor(getActivity(), R.color.tab_selection));
                }else{
                    tabLayout.setTabTextColors(ContextCompat.getColor(getActivity(), R.color.unselected_tab),ContextCompat.getColor(getActivity(), R.color.white));
    
                }
    
     // same thing goes with other tabs too
     // Just change your tab text on selected/deselected as above
    
        }
    
        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
            tab.setCustomView(null);
        }
    
        @Override
        public void onTabReselected(TabLayout.Tab tab) {
    
        }
    });
    

提交回复
热议问题