【发布时间】:2012-09-26 23:18:25
【问题描述】:
有没有办法设置 TabBar 的 selected 选项卡,使其包含渐变背景色?我原以为结合fillColors 和fillAplhas 将是要使用的样式,但这会设置其他 non selected 选项卡背景颜色,如果您运行下面的代码,您可以看到。
目标是让最终用户选择所选选项卡实例的背景颜色(例如使用 ColorPicker)。我想对这种颜色应用一些渐变效果。
任何帮助都将不胜感激,因为我一直在努力让它工作太久。我在谷歌上无休止地搜索了这个,但仍然找不到有效的解决方案。
private function updateTabColor():void {
var selectedTabIndex : int = tabBar.selectedIndex;
var tab:Tab = Tab(tabBar.getChildAt(selectedTabIndex));
/* this works but not on the selected tab */
tab.setStyle("fillColors", ["#000000", "000000"]);
tab.setStyle("fillAlphas", [1.0, 0.4]);
/* when not commented and as expected, tab is red */
//tab.setStyle("backgroundColor", "red");
/* when not commented, doesn't work as it appears it's deprecated in 3.0 */
//tab.setStyle("selectedFillColors", "red");
}
<mx:TabBar id="tabBar" dataProvider="viewStack" width="100%" itemClick="{updateTabColor()}"/>
<mx:ViewStack id="viewStack" width="100%" height="100%">
<mx:Box id="tab1" label="tab1" width="100%" height="100%"/>
<mx:Box id="tab2" label="tab2" width="100%" height="100%"/>
<mx:Box id="tab3" label="tab3" width="100%" height="100%"/>
</mx:ViewStack>
【问题讨论】:
-
我建议使用这个在线工具作为一个简单的参考,有时这比翻阅文档更容易得到你想要的:examples.adobe.com/flex3/consulting/styleexplorer/… 如果这不起作用,我建议使用 Ctrl+ Shift+T 或 Ctrl 单击 TabBar 以打开源代码,如果它抱怨找不到它,请告诉我。在 Flex 中做任何你想做的最简单的方法是查看你依赖的源代码。
-
谢谢@shaunhusain - 我确实按照你昨天说的做了,但这并没有真正帮助。该示例只有一个 TabNavigator,它有点相似,但与 TabBar 无关。 selected 选项卡实例没有样式示例。这肯定是标准要求吧?
-
没问题,但据我所知,TabNavigator 只是一个 ViewStack,它已经为你组合了一个 TabBar,所以它不应该有太大的变化,只是假设你能得到你想要的东西在那里它会帮助你在 TabBar 上找到样式名称,我会试着在这里检查几分钟,看看我是否能弄清楚你在寻找什么。
-
好吧,只是看了一眼,然后在谷歌上搜索了一下,认为我有一个很好的答案的链接
标签: actionscript-3 apache-flex flex3