Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

如何改变列表框当前项的背景

From Wiki
Jump to: navigation, search
Article Metadata

代码示例
兼容于
文章
翻译:
chenziteng
最后由 hamishwillee 在 06 Aug 2012 编辑

概述

S60第三版的列表框支持皮肤,它的列表项背景实际上是由九张小图拼成的一张图(九张小图包括四条边、四个角以及中间的小图),每张小图都有一个类似KAknsIIDQsnFrListCenter的ID标识,ID的定义参见系统头文件AknsConstants.h。

以下代码演示了如何将当前列表项背景的中心小图替换成自定义的图片。

void CTdjgmcqeListBox::ConstructL( 
const TRect& aRect,
const CCoeControl* aParent,
MEikCommandObserver* aCommandObserver )
{
...
_LIT(KMbmFile, "z:\\resource\\apps\\Tdjgmcqe.mbm"); // not good to use a hard-coded path, but anyway this is just a sample code.
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
CAknsItemData* item = skin->GetCachedItemData(KAknsIIDQsnFrListCenter);
if(item==NULL)
{
item = skin->CreateUncachedItemDataL(KAknsIIDQsnFrListCenter);
}
if(item->Type()==EAknsITMaskedBitmap)
{
// override the skin image for listbox highlighted item background (central part)
CAknsItemDef* def = AknsUtils::CreateMaskedBitmapItemDefL(KAknsIIDQsnFrListCenter, KMbmFile, EMbmTdjgmcqeListboxitemhightlightcenter, EMbmTdjgmcqeListboxitemhightlightcentermask);
skin->SetLocalItemDefL(def);
}
/*
// change the highlighted item text color
iListBox->ItemDrawer()->SetHighlightedTextColor(KRgbRed);
*/
}

源代码

完整的示例程序 (如果想在真机上运行请将硬编码的mbm路径从z:改为c:或者e:):

Tdjgmcqe(ListBoxItemHighlight).zip

屏幕截图:

Tdjgmcqe(ListBoxItemHighlight).PNG

This page was last modified on 6 August 2012, at 06:20.
132 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×