Skip to content Skip to sidebar Skip to footer

How Do I Make All Tabs In A Tabhost Unselected

I need to show tab content on occasion, otherwise the area must be filled with 'non-tabhost' data.However, tabs should be visible and when user clicks any of those tabs 'non-tabhos

Solution 1:

What I usually do is, add an extra Tab and use setVisibility(View.GONE) to hide it. THis will just hide the tab button from the user, and the Tab will still be there, in the "background" and you can programmatically select it, by using tabHost.setCurrentTab(0). I also usually keep this tab as the first one.

Solution 2:

1.copy the code where you want to tabs make unselected

 tabLayout.setSelectedTabIndicatorColor(Color.WHITE);
                    tabLayout.setTabTextColors(Color.BLACK, Color.BLACK);

2.Override on Tabselected Listener and paste the following code

tabLayout.setOnTabSelectedListener(newTabLayout.OnTabSelectedListener() {
            @Override`enter code here
            publicvoidonTabSelected(TabLayout.Tab tab) {
                 tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#EB1C23"));
                tabLayout.setTabTextColors(Color.BLACK, Color.RED);
              viewPager.setCurrentItem(position);
}


            @OverridepublicvoidonTabUnselected(TabLayout.Tab tab) {

            }

            @OverridepublicvoidonTabReselected(TabLayout.Tab tab) {
               tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#EB1C23"));
                tabLayout.setTabTextColors(Color.BLACK, Color.RED);
              viewPager.setCurrentItem(position);
            }
        });

Post a Comment for "How Do I Make All Tabs In A Tabhost Unselected"