[英]How to set the text color of a row in a Spark DataGrid
I have had a lot of trouble with setting the row color and text color in Spark DataGrids more times than I can remember. 我在设置Spark DataGrids中的行颜色和文本颜色时遇到了很多麻烦,这超出了我的记忆。 This post shows how to set it.
这篇文章展示了如何设置它。
To set the text styles on a grid item row we need to create a new DataGrid Item Renderer. 要在网格项目行上设置文本样式,我们需要创建一个新的DataGrid项目渲染器。
Unfortunately, when we create a new ItemRenderer in Flash Builder it only creates a bare bones ItemRenderer with only a label. 不幸的是,当我们在Flash Builder中创建一个新的ItemRenderer时,它仅创建一个只有标签的裸露的ItemRenderer。 By default it doesn't add any support for states.
默认情况下,它不添加任何对状态的支持。
To set the styles we need we need to create a new ItemRenderer with hover states and then set the color values for those states. 要设置样式,我们需要创建一个具有悬停状态的新ItemRenderer,然后为这些状态设置颜色值。
<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
clipAndEnableScrolling="true">
<s:states>
<s:State name="normal" />
<s:State name="hovered" />
<s:State name="down" />
<s:State name="selected" />
</s:states>
<s:Label id="labelDisplay" top="9" left="7"
color.normal="#171515"
color.hovered="#FFFFFF"
color.down="#FFFFFF"
color.selected="#FFFFFF"
/>
</s:GridItemRenderer>
We then need to point the DataGrid to our item renderer: 然后,我们需要将DataGrid指向项目渲染器:
<s:DataGrid itemRenderer="view.renderers.AbstractDataGridItemRenderer">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.