如何更改ButtonBar中的标签 - 简单的测试用例和附加的屏幕截图

时间:2013-08-05 13:26:14

标签: flex flex4 flex4.5 flex-mobile buttonbar

在Flex Mobile应用中,我希望底部有ButtonBar,我需要更改其按钮的标签:

enter image description here

(我不想在这里使用TabbedViewNavigatorApplication,因为我的所有逻辑都在一个View中,其顶部是ActionBar,底部是ButtonBar。)

所以我准备了一个非常简单的测试用例来证明我的问题。

请在Flash Builder中创建一个“空白”Flex移动项目并将我的2个文件(下方)放入其中,您将看到我的问题 - 触摸底部的按钮不会更改右侧按钮的标签)。

TestAC.mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               applicationDPI="160">
    <fx:Script>
        <![CDATA[
            import spark.events.IndexChangeEvent;
            import spark.skins.mobile.TabbedViewNavigatorTabBarSkin;

            private function handleTabs(event:IndexChangeEvent):void {
                trace(_tabBar.selectedIndex);
                _tabs[2].label = String(1 + _tabBar.selectedIndex);
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <s:MultiDPIBitmapSource id="CHAT" 
            source160dpi="@Embed('chat.png')"
            source240dpi="@Embed('chat.png')"
            source320dpi="@Embed('chat.png')" />

        <s:ArrayCollection id="_tabs">
            <fx:Object label="One" />
            <fx:Object label="Two" />
            <fx:Object label="Three" icon="{CHAT}" />
        </s:ArrayCollection>
    </fx:Declarations>

    <s:ButtonBar id="_tabBar"
                 requireSelection="true" 
                 width="100%" 
                 bottom="0"
                 skinClass="spark.skins.mobile.TabbedViewNavigatorTabBarSkin"
                 dataProvider="{_tabs}"
                 change="handleTabs(event)">
    </s:ButtonBar>

</s:Application>

chat.png:

enter image description here

1 个答案:

答案 0 :(得分:0)

好的,将_tabs.refresh();添加到handleTabs有所帮助。