标题:如何从当前主题中获取grid文本颜色
TSS000596
TSS000596
设备, 软件 版本:
S60 2nd Edition, S60 3rd Edition
详细描述
我们可以从当前主题中获取自定义grid(CAknGrid)的文本颜色,但在设置时第二版和第三版略有不同。
解决方案
S60第二版:
正常状态下以及高亮状态下,可以在CCoeControl派生的Container的SizeChanged()方法中设置(该Container拥有grid)。
下列是示例代码:
TRgb textColor; // text color when not highlighted MAknsSkinInstance* skin = AknsUtils::SkinInstance(); AknsUtils::GetCachedColor( skin, textColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG9 ); TRgb highlightColor; // text color when highlighted AknsUtils::GetCachedColor( skin, highlightColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG11 ); iGrid->ItemDrawer()->SetTextColor( textColor ); // iGrid is of type CAknGrid iGrid->ItemDrawer()->SetHighlightedTextColor( highlightColor );
但这里ItemDrawer()->SetTextColor()方法无法用在S60第三版上。
S60第三版:
设置颜色要通过CFormattedCellListBoxData对象,可以做如下操作:
TRgb textColor; // text color when not highlighted MAknsSkinInstance* skin = AknsUtils::SkinInstance(); AknsUtils::GetCachedColor( skin, textColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG9 ); TRgb highlightColor; // text color when highlighted AknsUtils::GetCachedColor( skin, highlightColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG11 ); CFormattedCellListBoxData::TColors colors; colors.iText = textColor; colors.iHighlightedText = highlightColor; iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL( 0, colors ); iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL( 1, colors ); iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL( 3, colors );
上面的代码可以加载在grid的SizeChanged()函数中,否则默认的SizeChanged()会覆盖自定义的操作。注意SetUpFormTextCell()函数的调用必须要在设置文本颜色前调用.