Using Skin in Symbian is a tough task for new users like me. After a day of hard work, I tried several cases and summarized them.
1. One sentence Method
The most basic trick is to add a sentence to constructl () in Appui. As follows:
void CTestMIMAppUi::ConstructL() {
BaseConstructL(CAknAppUi::EAknEnableSkin);
//add your code here...
}
The above statement can basically make most of the controls transparent and display the system skin.
However, sometimes we find that some controls (such as the ceikedwin) still display an ugly white background. At this time, we need to do some extra work.
Modify the header file of the container and add a member variable:
CAknsBasicBackgroundControlContext* iBgContext;
Then initialize it in the corresponding constructl function:
iBgContext = CAknsBasicBackgroundControlContext::NewL(KAknsIIDQsnBgAreaMainIdle,aRect,ETrue);
Here, you can choose other kaknsiidqsbgareamainidle.
Then, because ceidedwin has a convenient member method setskinbackgroundcontrolcontextl, the following code is simple:
iEdWin=new(ELeave)CEikEdwin;
CleanupStack::PushL(iEdWin);
iEdWin->SetContainerWindowL(*this);
iEdWin->ConstructL();
iEdWin->SetSkinBackgroundControlContextL(iBgContext);
iEdWin->SetExtentToWholeScreen();
iEdWin->SetFocus(ETrue);
iEdWin->ActivateL();
CleanupStack::Pop(iEdWin);
In this way, you can. Do not forget to delete it during structure analysis.
2. The ultimate method for displaying system skin
Further, if the widget doesn't have such a convenient Member, let's set its background, there is also a way (refer to http://www.newlc.com/Enable-Skin-support-in-your.html ).
You can easily add a mopsupplyobject declaration in the H file:
TTypeUid::Ptr MopSupplyObject(TTypeUid aId);
In the implementation process, the contructl does not need iedwin-> setskinbackgroundcontrolcontextl, but is processed in three functions respectively:
void CTestMIMEdtContainer::Draw(const TRect& aRect) const {
CWindowGc& gc = SystemGc();
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
AknsDrawUtils::Background( skin, cc, this, gc, aRect );
}
void CTestMIMEdtContainer::SizeChanged() {
if(iBgContext)
{
iBgContext->SetRect(Rect());
if ( &Window() )
{
iBgContext->SetParentPos( PositionRelativeToScreen() );
}
}
DrawNow();
}
TTypeUid::Ptr CTestMIMEdtContainer::MopSupplyObject(TTypeUid aId)
{
if (iBgContext )
{
return MAknsControlContext::SupplyMopObject( aId, iBgContext );
}
return CCoeControl::MopSupplyObject(aId);
}
This also allows the control to transparently display the system skin.
3. Display Custom Skin
The key to display a custom skin is how the ibgcontext member gets it out. The first parameter of newl () is something defined by the system. Now we need to customize it.
Similarly, first modify an H file and add a member:
TAknsItemID aSkinItem;
Then implement the contructl function in the file. We need to extract the image from the MIF file to make it a background:
TFileName iMFileName;
iMFileName.Copy(KMifFileName);
CompleteWithAppPath(iMFileName);
aSkinItem.iMinor = 0xE2139689;
aSkinItem.iMajor = 1 ;
CAknsItemDef* mainBgItemDef = AknsUtils::CreateBitmapItemDefL(aSkinItem, iMFileName, EMbmTestmimGrid);
AknsUtils::SkinInstance()->SetLocalItemDefL( mainBgItemDef );
iBgContext = CAknsBasicBackgroundControlContext::NewL(aSkinItem,aRect,ETrue );
Here, kmiffilename is the defined resource MIF file (similar to the method for loading resource images in other examples ).