×
Namespaces

Variants
Actions

如何定制列表框的背景

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): S60 Emulator
CompatibilityArticle
Keywords: KAknsIIDQsnBgAreaMainListGene, MAknsSkinInstance, AknsUtils, SkinInstance, CAknsItemData, GetCachedItemData, EAknsITMaskedBitmap, CreateMaskedBitmapItemDefL, CreateBitmapItemDefL
Created: chenziteng (07 Oct 2009)
Last edited: hamishwillee (30 May 2013)

概述

S60第三版的列表框支持皮肤,它的背景实际上是一张图,这张图由KAknsIIDQsnBgAreaMainListGene标识,类似的ID的定义参见系统头文件AknsConstants.h。

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

void CTdjgmcqeListBox::ConstructL( 
const TRect& aRect,
const CCoeControl* aParent,
MEikCommandObserver* aCommandObserver )
{
...
_LIT(KMbmFile, "z:\\resource\\apps\\Tdjgmcqe.mbm");
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
CAknsItemData* item = skin->GetCachedItemData(KAknsIIDQsnBgAreaMainListGene);
if(item==NULL)
{
item = skin->CreateUncachedItemDataL(KAknsIIDQsnBgAreaMainListGene);
}
if(item->Type()==EAknsITMaskedBitmap)
{
CAknsItemDef* def = AknsUtils::CreateMaskedBitmapItemDefL(KAknsIIDQsnBgAreaMainListGene, KMbmFile, EMbmTdjgmcqeMainarea, EMbmTdjgmcqeMainareamask);
skin->SetLocalItemDefL(def);
}
else
{
CAknsItemDef* def = AknsUtils::CreateBitmapItemDefL(KAknsIIDQsnBgAreaMainListGene, KMbmFile, EMbmTdjgmcqeMainarea);
skin->SetLocalItemDefL(def);
}
...
}

源代码

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

Tdjgmcqe(ListBoxCustomBackground).zip

屏幕截图 (第一张: 平常的列表框, 第二张: 拥有定制背景图的列表框):

Tdjgmcqe(NormalListBox).PNGTdjgmcqe(ListBoxCustomBackground).PNG

相关文档

How to use custom background for listbox

How to change the highlighted listbox item background

How to use custom background for text editors

This page was last modified on 30 May 2013, at 06:21.
19 page views in the last 30 days.