Reputation: 4287
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-tabhost" must be hidden and appropriate tab content must become visible.
It's something connected to a fake tab creation ?
Give an example of creating TabHost with tabs unselected. Thanks.
Upvotes: 0
Views: 2564
Reputation: 265
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(new TabLayout.OnTabSelectedListener() {
@Override`enter code here
public void onTabSelected(TabLayout.Tab tab) {
tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#EB1C23"));
tabLayout.setTabTextColors(Color.BLACK, Color.RED);
viewPager.setCurrentItem(position);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#EB1C23"));
tabLayout.setTabTextColors(Color.BLACK, Color.RED);
viewPager.setCurrentItem(position);
}
});
Upvotes: 3
Reputation: 72341
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.
Upvotes: 3