在 Spark TabBar 中隐藏选项卡 [英] Hiding a tab in a Spark TabBar
问题描述
我有一个 spark TabBar,我想从外部用户输入(即复选框检查)中隐藏和显示它的一些元素
I have a spark TabBar and I want to hide and show some elements of it from an external user input (namely a checkbox check)
我在更改选项卡可见性时遇到问题.它们当前始终显示.
I am having trouble changing the tabs visibility. They are currently always shown.
有人知道吗?我在 mx TabBar 上看到了 getTabAt,但选项卡的外观很重要,要求它看起来像选项卡栏而不是按钮栏.
Does anyone have any idea? I have seen a getTabAt on the mx TabBar but the look of the tab is important and the requirement is for it to look like a tab bar rather than a button bar.
我的标签以及隐藏和显示代码如下:
My code for the tabs and for hiding and showing is below:
<fx:Script>
<![CDATA[
import mx.containers.VBox;
import mx.controls.Label;
private function onCreationComplete():void {
var vbox1:VBox = new VBox();
vbox1.label = "Tab 1";
var lbl1:Label = new Label()
lbl1.text = "Panel1";
vbox1.addChild(lbl1);
dp.addChild(vbox1);
var vbox2:VBox = new VBox();
vbox2.label = "Tab 2";
var lbl2:Label = new Label()
lbl2.text = "Panel 2";
vbox2.addChild(lbl2);
dp.addChild(vbox2);
}
private function showTab(event:MouseEvent):void {
makeVisible(true);
}
private function hideTab(event:MouseEvent):void {
makeVisible(false);
}
private function makeVisible(vis:Boolean):void {
VBox(dp.getChildAt(0)).visible = vis;
VBox(dp.getChildAt(0)).enabled = vis;
VBox(dp.getChildAt(0)).includeInLayout = vis;
}
]]>
</fx:Script>
<s:VGroup>
<s:TabBar id="tabNavigator" width="100%" height="100%" dataProvider="{dp}"/>
<mx:ViewStack width="100%" height="100%" id="dp" borderStyle="solid"/>
<s:Button click="showTab(event)" label="show Tab"/>
<s:Button click="hideTab(event)" label="hide Tab"/>
</s:VGroup>
任何建议都非常受欢迎
谢谢
推荐答案
此功能将隐藏特定索引处的选项卡.如果您没有 includeInLayout 那么选项卡就会消失并留下一个洞.
This function will hide a tab at a particular index. If you do not have the includeInLayout then the tab disappears and leaves a hole.
private function setTabEnabled(index:int, enabled:Boolean):void {
var theTab:UIComponent = tabNavigator.dataGroup.getElementAt(index) as UIComponent;
if (theTab)
theTab.visible = enabled;
theTab.includeInLayout = enabled;
}
}
这篇关于在 Spark TabBar 中隐藏选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!