Disable/enable tabs: change color to original
I've got the following code:
\\Disable
tabHost.getTabWidget().g开发者_运维知识库etChildTabViewAt(3).setEnabled(false);
tabHost.getTabWidget().getChildTabViewAt(3).setBackgroundColor(Color.rgb(102, 102, 102));
And:
\\Enable
tabHost.getTabWidget().getChildTabViewAt(3).setEnabled(true);
\\HOWTO?
How can I revert the color of the disabled tab back to it's original color (with gradient and stuff) when I enable it again?
If you use a Drawable as background you can use:
savedBackground = tabHost.getTabWidget().getChildTabViewAt(3).getBackground();
// Disable your tab
And once you enable it:
tabHost.getTabWidget().getChildTabViewAt(3).setEnabled(true);
tabHost.getTabWidget().getChildTabViewAt(3).getChildTabViewAt(3).setBackgroundDrawable (savedBackground );
You can't extract a Color value from the original enabled tab, as it uses a Drawable. However, I don't believe anything is stopping you from switching between a Drawable and a Color for enabled/disabled states. So my suggestion is to store the original background Drawable from the tab View using View.getBackground(), and when it comes time to enable the tab again, you can then pass that stored drawable to View.setBackgroundDrawable(Drawable).
精彩评论