flex 4:mx|Tree 如何禁用悬停和选择颜色?
这是与我的第一个问题相关的第二个问题:
我想禁用悬停和选择颜色,以便当用户选择项目时,其背景不会改变颜色。这怎么可能?
更新
我不想选择选择和悬停颜色。背景包含图像,因此没有用处。我需要完全禁用颜色。
我尝试覆盖 Tree 类的另一个更新
但没有成功。
这是覆盖树类的类:
package components.popups.WelcomeBack {
import mx.controls.listClasses.IListItemRenderer;
import mx.controls.Tree;
/**
* @author ufk
*/
public class TreeNoSelection extends Tree {
protected override function drawItem(item:IListItemRenderer,
selected:Boolean = false,
highlighted:Boolean = false,
caret:Boolean = false,
transition:Boolean = false):void
{
super.drawItem(item, false, false, false, transition);
}
}
}
这是我实际的树组件:
<?xml version="1.0" encoding="utf-8"?>
<WelcomeBack:TreeNoSelection xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:WelcomeBack="components.popups.WelcomeBack.*" folderClosedIcon="{null}" defaultLeafIcon="{null}"
folderOpenIcon="{null}"
showRoot="false"
allowMultipleSelection="false" allowDragSelection="false" labelField="@label">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import ItemRenderer.WelcomeBackTreeItemRenderer;
private var _themeLibrary:Object;
public function get themeLibrary():Object {
return this._themeLibrary;
}
public function set themeLibrary(tl:Object):void {
this._themeLibrary=tl;
var cf:ClassFactory = new ClassFactory();
cf.generator = ItemRenderer.WelcomeBackTreeItemRenderer;
cf.properties = {
_themeLibrary:this._themeLibrary
};
this.itemRenderer=cf;
}
]]>
</fx:Script>
</WelcomeBack:TreeNoSelection>
谢谢
this is a 2nd question related to my first question at:
Flex 4: mx|tree - how can i disable items selection?
I want to disable the hover and selection colors so when a user selects an item it's background won't change color. how is that possible?
update
i do not want to choose the selection and hover colors. the background contains an image so it won't be useful. i need to completely disable the colors.
another update
i tried to override the Tree class but with no luck.
this is the class that overrides the tree Class:
package components.popups.WelcomeBack {
import mx.controls.listClasses.IListItemRenderer;
import mx.controls.Tree;
/**
* @author ufk
*/
public class TreeNoSelection extends Tree {
protected override function drawItem(item:IListItemRenderer,
selected:Boolean = false,
highlighted:Boolean = false,
caret:Boolean = false,
transition:Boolean = false):void
{
super.drawItem(item, false, false, false, transition);
}
}
}
and this is my actual tree component:
<?xml version="1.0" encoding="utf-8"?>
<WelcomeBack:TreeNoSelection xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:WelcomeBack="components.popups.WelcomeBack.*" folderClosedIcon="{null}" defaultLeafIcon="{null}"
folderOpenIcon="{null}"
showRoot="false"
allowMultipleSelection="false" allowDragSelection="false" labelField="@label">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import ItemRenderer.WelcomeBackTreeItemRenderer;
private var _themeLibrary:Object;
public function get themeLibrary():Object {
return this._themeLibrary;
}
public function set themeLibrary(tl:Object):void {
this._themeLibrary=tl;
var cf:ClassFactory = new ClassFactory();
cf.generator = ItemRenderer.WelcomeBackTreeItemRenderer;
cf.properties = {
_themeLibrary:this._themeLibrary
};
this.itemRenderer=cf;
}
]]>
</fx:Script>
</WelcomeBack:TreeNoSelection>
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有好消息和坏消息。好消息是这真的很容易。坏消息是您需要对树进行子类化。
因此,这里发生的情况是,我们拦截了 drawItem 方法并调用超类上的该方法,欺骗它认为没有任何内容被选中、突出显示或“插入”。当您通过键盘更改选择时,会出现插入符号。不确定转换参数的用途,如果仍然有一些效果困扰您,您可以将其发送为 false。
编辑
在查看了相关问题后,我发现问题的根源是使用新的 Spark 架构的项目渲染器,这意味着渲染器负责对特殊状态(选定、突出显示,显示插入符号)。因此,当使用 Spark 项目渲染器时,还有其他 3 个功能也需要重写:
奖励 - 重写 isItemSelectable 以防止在单击某个项目时进行选择(您仍然可以通过键盘选择它们,尽管不会有任何视觉提示):
I've got good news and bad news. The good news is that it's really easy. The bad news is that you need to subclass the Tree.
So what happens here is that we intercept the drawItem method and call the method on the superclass fooling it into thinking there's nothing selected, highlighted or "careted". The caret is for when you change selection by keyboard. Not sure what the transition parameter is for, you can send it as always false if there're still some effects bothering you.
Edit
After taking a look at the related question, I found out that the root of the problem is the item renderer using the new spark architecture, which means the renderers are responsible with reacting to special states (selected, highlighted, show caret). So when using the spark item renderer there are other 3 functions that also need overriding:
Bonus - override isItemSelectable to prevent selection when clicking on an item (you can still select them via keyboard, although there will be no visual hint of that):
您可以在树上使用 rollOverColor 和 selectionColor 样式。设置样式的方法有多种,但在这里我将它们设置为内联白色,将颜色更改为背景颜色。
You can use the rollOverColor and selectionColor style on the Tree. There are different ways to set the styles but here I'm setting them inline to white, change the color to whatever your background color is.
您也许可以通过 jss 的方法使用 4 通道颜色:
...在颜色选择中包括 alpha 通道(完全透明)。
You might be able to use 4-channel colors with jss's approach:
...including the alpha channel (at full transparent) in the color choice.