How to hide a tab in Android tab layout?

后端 未结 2 1062
半阙折子戏
半阙折子戏 2020-12-11 03:13

I have a tab layout containing 3 tabs. I want to add 4th tab at run time and hide this tab after some time. Please let me know how to hide a tab in Android.

2条回答
  •  爱一瞬间的悲伤
    2020-12-11 03:54

    Well, I'm building an app that use a FragmentPagerAdapter as SectionsPagerAdapter in an activity. This activity was generated by AS and its layout has a TabLayout with some TabItems.

    I wanted to hide one of them if var hide is false. Then I used:

    Toolbar toolbar = findViewById(R.id.sectionBar);
    if(!hide) {
        TabLayout.Tab tab = tabLayout.getTabAt(2);
        if(tab!=null) {
            tabLayout.removeTab(tab);
        }
    }
    

    I know that remove is not hide but it was my solution.

提交回复
热议问题