在 flex 中更改单个选项卡样式 [英] Changing individual tab style in flex

查看:16
本文介绍了在 flex 中更改单个选项卡样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想出了一种在运行时更改标签样式的方法,其逻辑如下:

I have figured out a way to change the style of tabs at run time with following logic:

var cssStyle:CSSStyleDeclaration = StyleManager.getStyleDeclaration(".MyTabs");
  cssStyle.setStyle("borderColor", "red");

但是这里.MyTabs"类适用于第一个和最后一个选项卡之间的所有选项卡.根据 getStyleDeclaration javadoc,它只接受类选择器"和类型选择器",而不接受 id 选择器.

But here ".MyTabs" class is applicable to all the tabs between first and last tab. As per getStyleDeclaration javadoc, it only accepts "class selector" and "type selector" not the id selector.

如何在运行时更改单个选项卡样式?

How can I change the individual tab style at run time?

推荐答案

另一位用户指出了一个我不知为何错过的方法,它允许您将 Tab 作为按钮访问并从那里设置样式.

Another user pointed out a method that I had somehow missed, allowing you to access a Tab as a Buttom and style it from there.

var t:Button = theTabs.getTabAt(index);

Tab 扩展了 Button,因此您可能需要以下解决方案来解决某些问题,但对于基本样式而言,这应该足够了.

Tab extends Button, so there may be some things you would need the below solution for, but for basic styling this should be enough.

@Sebastian 的回答适用于 TabBar,我知道你没有,因为这是你问的第三个相同的问题.为了在 TabNavigator 上设置选项卡的样式,您需要访问内部 TabBar.

@Sebastian's answer works for a TabBar, which I know you don't have, as this is the third identical question you've asked. In order to style the tabs on a TabNavigator, you need to access the internal TabBar.

//this import may not auto-complete for you
import mx.controls.tabBarClasses.Tab;

var t:Tab = theTabs.mx_internal::getTabBar().getChildAt(index);

现在您可以随意设置样式,如 Sebastian 的回答所示.

Now you can feel free to set the styles, as shown in Sebastian's answer.

这篇关于在 flex 中更改单个选项卡样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆