I have an application where I have 5 tabs set up, and I it works perfectly except for one issue I noticed recently. On large screen sizes, for some reason, the tabs are transparent, I only noticed this when I tried out the application on one of my colleagues large android device. So I then set up the emulator to a large screen size of 10 inches, and its the same thing.
So in order to fix this, I used this code
public static void setTabColor(TabHost tabhost) {
for (int i = 0; i < tabhost.getTabWidget().getChildCount(); i++) {
tabhost.getTabWidget().getChildAt(i)
.setBackgroundColor(Color.parseColor("#292929")); // unselected
// }
tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab())
.setBackgroundColor(Color.parseColor("#8b8b8b")); // selected
}
}
Then I use OnTabChangeListener and place
setTabColor(tabHost);
under each tab change. This fixed the issue so that the tab colours are the same for all screen sizes. However the problem now is that the divider is gone. I tried using
tabHost.getTabWidget().setDividerDrawable(R.drawable.separator);
but the problem is this piece of code must be called before you set the content of the tabs and seeing I have set up
setTabColor(tabHost);
on every tab change, it makes it rather useless as it works when application loads up, but when you switch tab, it is gone again, and I can’t call it again otherwise application will crash.
Does anyone have any suggestions as to how I can fix this issue? And also could someone explain to me why the tabs are transparent on larger screens? Why does Android do this?
Thanks in advance for any assistance
I fixed this issue, turns out I could just color the tabs in and did not need to use the tab divider after all. Used this method here
To color in tabs