2011-03-24 64 views
1

我有下面的代码:禁用/启用选项卡:颜色改变,原来

\\Disable 
tabHost.getTabWidget().getChildTabViewAt(3).setEnabled(false); 
tabHost.getTabWidget().getChildTabViewAt(3).setBackgroundColor(Color.rgb(102, 102, 102)); 

和:

\\Enable 
tabHost.getTabWidget().getChildTabViewAt(3).setEnabled(true); 
\\HOWTO? 

我如何能恢复的禁用标签的颜色回到它的原颜色(与渐变和东西),当我再次启用它?

回答

3

如果使用可绘制作为背景,你可以使用:

savedBackground = tabHost.getTabWidget().getChildTabViewAt(3).getBackground(); 
// Disable your tab 

而一旦你打开它:

tabHost.getTabWidget().getChildTabViewAt(3).setEnabled(true); 
tabHost.getTabWidget().getChildTabViewAt(3).getChildTabViewAt(3).setBackgroundDrawable (savedBackground); 
+0

谢谢,我以为我尝试过这样的事情,但有错误。无论如何,当我这样做时,它就会起作用! – nhaarman 2011-03-24 17:58:01

1

您无法从原始启用选项卡中提取颜色值,因为它使用Drawable。不过,我不相信任何东西会阻止您在启用/禁用状态之间切换Drawable和Color。所以我的建议是使用View.getBackground()从标签View中存储原始背景Drawable,当它再次启用标签时,您可以将存储的drawable传递给View.setBackgroundDrawable(Drawable)。

+0

谢谢,它的工作原理(显然相同的答案@moss) – nhaarman 2011-03-24 17:58:42

+0

+1相同在同一时间回答:D尼斯hehehe – Moss 2011-03-28 18:07:37

相关问题