Dom*_*icM 4 apache-flex itemrenderer background-color flex4 flex4.5
我有一个项目渲染器,我想更改默认颜色:
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
initialize="init(event)"
creationComplete="created(event)"
dataChange="created(event)"
width="100%"
maxWidth="{FlexGlobals.topLevelApplication.width}"
contentBackgroundColor.hovered="0xff0018"
focusColor="0xff00ff"
contentBackgroundAlpha="0.8">
<s:states>
<s:State name="normal"/>
<s:State name="hovered"/>
<s:State name="selected"/>
</s:states>
Run Code Online (Sandbox Code Playgroud)
上述代码中的样式无效.
我也尝试将contentBackgroundColor添加到List元素,但只更改了列表的背景而不是项目.
css也不起作用:
s|ItemRenderer{
backgroundColor:#2e2e2e;
}
Run Code Online (Sandbox Code Playgroud)
如何更改项呈示器的背景颜色?
我知道我可以去皮,但这对于一个简单的颜色变化来说是一种过度杀戮而且我很肯定我几年前都没有去皮.
起初总是有点混乱.在我看来,样式名称选择不当.血淋淋的细节都在班级的drawBackground()方法中ItemRenderer.
的contentBackgroundColor风格是你可以在设置上的List组件本身,这对渲染没有任何影响.它将填充列表的背景颜色,但通常渲染器占据所有区域,因此您永远不会看到它.例如,如果您的列表很高但只有1或2个项目(因此底部的空间不被渲染器覆盖),它将是可见的.
设置渲染器的背景颜色:
而不是使用contentBackgroundColor,使用alernatingItemColors风格.此样式需要一组值.如果您只想要一种颜色,只需在数组中放入一个元素:
alternatingItemColors="[#c0c0c0]"
Run Code Online (Sandbox Code Playgroud)
从查看代码中drawBackground(),如果要在背景颜色上设置alpha,则必须自己绘制背景(参见下文).
您可能希望设置的其他背景相关样式:
downColorselectionColorrollOverColor要绘制自己的背景颜色:
将该autoDrawBackground属性设置为false.这意味着您现在必须为所有各种渲染器状态("正常","选定","悬停"等)绘制自己的颜色.幸运的是,您可以在渲染器中使用与您在上面选择的背景对象上使用的相同状态语法("Rect"等).
<s:ItemRenderer autodrawBackground="false">
<s:states>
<s:State name="normal"/>
<s:State name="hovered"/>
<s:State name="selected"/>
</s:states>
<s:Rect id="theBackgroundObject" top="0" bottom="0" left="0" right="0">
<s:fill>
<s:SolidColor color="#FF0000" color.hovered="#00FF00"
alpha="1" alpha.hovered=".5" />
</s:fill>
</s:Rect>
</s:ItemRenderer>
Run Code Online (Sandbox Code Playgroud)