简体   繁体   English

在flex中运行时更改选项卡边框颜色

[英]Changing tab border color at run time in flex

How can I change border color of tab in tab navigator control at runtime? 如何在运行时更改选项卡导航器控件中选项卡的边框颜色? I am trying to access it with its id "mytab" and update it's style. 我试图用它的id“mytab”访问它并更新它的样式。

this.mytab.setStyle("bordercolor","red");

A TabNavigator has multiple tabs and I have to change style of few tabs based on some logic. TabNavigator有多个选项卡,我必须根据某些逻辑更改几个选项卡的样式。 StyleDeclaration is applicable for all the tabs under tab navigoter but how can use CSSStyleDeclaration based on componentid? StyleDeclaration适用于tab navigoter下的所有选项卡,但如何使用基于componentid的CSSStyleDeclaration? The only shortfall with this approach is that Style can not be changed for individual tab. 这种方法唯一的缺点是不能为单个选项卡更改Style。

Setting the style directly on the TabNavigator won't work. 直接在TabNavigator上设置样式将不起作用。 You have to set the tabStyleName property on TabNavigator and then create a style with the same name, which will be applied to your tabs. 您必须在TabNavigator上设置tabStyleName属性,然后创建一个具有相同名称的样式,该样式将应用于选项卡。 It is the same strategy as my answer to your other question ; 这与我对你的另一个问题的回答是一样的策略; just set the borderColor style instead. 只需设置borderColor样式。


If you really need to set the style dynamically at runtime, you can retrieve the CSSStyleDeclaration for the tabs and set it like so: 如果您确实需要在运行时动态设置样式,则可以检索选项卡的CSSStyleDeclaration并将其设置为:

  <mx:Style>
    .tabStyle {
      /* define an empty style so there is something to get using getStyleDeclaration */
    }
  </mx:Style>

  <mx:Script>
    <![CDATA[
      protected function changeStyle(event:MouseEvent):void
      {
        var cssStyle:CSSStyleDeclaration = StyleManager.getStyleDeclaration(".tabStyle");
        cssStyle.setStyle("borderColor", "red");
      }
    ]]>
  </mx:Script>

  <mx:TabNavigator id="mytab" width="200" height="200" tabStyleName="tabStyle">
    <mx:Canvas label="apple" width="100%" height="100%">
    </mx:Canvas>
    <mx:Canvas label="orange" width="100%" height="100%">
    </mx:Canvas>
    <mx:Canvas label="banana" width="100%" height="100%">
    </mx:Canvas>
  </mx:TabNavigator>

  <mx:Button x="10" y="218" label="Change Style!" click="changeStyle(event)"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM