需要有关此问题的帮助。我需要改变标题颜色。 以下不起作用:
column.setStyle(StyleNames.HEADER_COLORS, "#FF7F00");
答案 0 :(得分:4)
在AdvancedDataGrid
中设置一个列标题的背景颜色并不容易。您需要为标题使用自定义渲染器。
<强>用法强>
<fx:Style>
.yellowHeaderStyle {
backgroundColor: yellow;
backgroundAlpha: 1.0;
}
</fx:Style>
<mx:AdvancedDataGrid dataProvider="{dataProvider}">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="firstname" headerText="Firstname" />
<mx:AdvancedDataGridColumn dataField="lastname" headerText="Lastname"
headerRenderer="com.example.ColoredHeaderRenderer" headerStyleName="yellowHeaderStyle" />
</mx:columns>
</mx:AdvancedDataGrid>
<强> ColoredHeaderRenderer 强>
package com.example
{
import mx.controls.AdvancedDataGrid;
import mx.controls.advancedDataGridClasses.AdvancedDataGridHeaderRenderer;
import mx.controls.listClasses.BaseListData;
[Style(name="backgroundColor", type="uint", format="Color")]
[Style(name="backgroundAlpha", type="Number")]
/**
* The ColoredHeaderRenderer extends the default header renderer for a AdvancedDataGrid
* control and adds styles for chaning the backgroundColor and backgroundAlpha.
*
* <p>Both styles (backgroundColor and backgroundAlpha) must me set.</p>
*/
public class ColoredHeaderRenderer extends AdvancedDataGridHeaderRenderer
{
private var grid:AdvancedDataGrid;
override public function set listData(value:BaseListData):void
{
super.listData = value;
grid = AdvancedDataGrid(value.owner);
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if (background)
{
background.graphics.clear();
background.graphics.beginFill(getStyle("backgroundColor"), getStyle("backgroundAlpha"));
// The function AdvancedDataGridBase.createHeaders() adds a padding to the top
// and bottom of the HeaderRenderer. Let's undo this...
background.graphics.drawRect(0, 0 - grid.getStyle("paddingTop"), unscaledWidth,
unscaledHeight + grid.getStyle("paddingTop") + grid.getStyle("paddingBottom") - 1);
background.graphics.endFill();
}
}
}
}