×
Namespaces

Variants
Actions
Revision as of 09:20, 6 August 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

From Nokia Developer 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 09:20.
63 page views in the last 30 days.
×