Setting skin for Symbian study notes 18

Source: Internet
Author: User

Reference from: http://blog.csdn.net/sharetop/archive/2008/07/15/2654055.aspx

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...
}

In the above sentence, most of the widgetsTransparentDisplay 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 does not have such a convenient Member, let's set itsBackground, There is also a way (refer to the 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 controlTransparentThe system skin is displayed.

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 ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.