使用symbian應用程序創建嚮導可以創建帶有皮膚支持的工程。使得你的應用程序可以很方便的使用系統皮膚。
創建方法如下:
1打開開始菜單s60sdk的目錄下Tools 然後選擇Application Wizard創建一個app
2在第二個嚮導頁面上你可以看到Add support for的選項,選擇下面的skins然後繼續創建。你就可以得到一個支持皮膚的工程了。
如果是一個已有工廠以前沒有支持皮膚功能,也可以手工添加。步驟如下
1) 在ui裏面 ui ConstructL函數裏面將原來的BaseConstructL();換成BaseConstructL( EAknEnableSkin );
2) Container 裏面加入頭文件
#include <AknsBasicBackgroundControlContext.h> //skin
3) container裏面添加成員變量 並在ConstructL裏面初始化它。
.h裏面加成員變量 MAknsControlContext* iBackGround; // for skins support
.cpp裏面ConstructL裏初始化
SetRect(aRect);
iBackGround = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, Rect(), EFalse );
放在setrect之後!!!!!!!否則無法看到皮膚
4) Container 的
Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
// TODO: Add your drawing code here
// example code...
// draw background
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
AknsDrawUtils::Background( skin, cc, this, gc, aRect );
}
5) Container 的
MopSupplyObject(TTypeUid aId)
{
if(aId.iUid == MAknsControlContext::ETypeId && iBackGround)
{
return MAknsControlContext::SupplyMopObject( aId, iBackGround);
}
return CCoeControl::MopSupplyObject( aId );
}
用下面的方法我們可以獲取系統皮膚的相關顏色:
TRgb color;
AknsUtils::GetCachedColor(skin,color,KAknsIIDQsnScrollColors,EAknsCIQsnIconColorsCG10);
我作了一個枚舉顏色的程序:
{
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
MAknsControlContext* cc = AknsDrawUtils::ControlContext( aMop );
TRgb color;
TInt columnNum=4;
TInt result=KErrNone;
TInt index=0;
while(result==KErrNone)
{
result=AknsUtils::GetCachedColor(skin,color,aID,index);
if(result!=KErrNone)
{
RDebug::Print(aName);
RDebug::Print(_L("GetColorFaild,index=%d"),index);
}
else
{
RDebug::Print(aName);
RDebug::Print(_L("[%d]Color(%d,%d,%d)"),index,color.Red(),color.Green(),color.Blue());
}
TInt x,y;
x=index%columnNum;
y=index/columnNum;
TRect colorRect(TPoint(10*x+1,10*y+1),TSize(8,8));
aGc.SetBrushColor(color);
aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
aGc.DrawRoundRect(colorRect,TSize(2,2));
index++;
}
}
這是在不同皮膚下取到的顏色對比:
最早發表於:http://blog.csdn.net/windcao/archive/2007/09/10/1779413.aspx