Using Theme in an Application

本文介绍如何在S60平台2.0版本后的应用程序中使用主题皮肤,包括链接库文件、启用皮肤支持、创建背景控制上下文及绘制背景位图等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Using Theme in an Application

This article can tell you how to write a enable skins application.
You can use theme in an Application after version in Series 60 Platform 2.0. the following content will tell you how to do these step by step.
Author Website: http://www.symbianer.com
Link against aknskins.lib and include files
Add the libray named aknskins.lib in SkinSample.mmp
 
Code:
LIBRARY aknskins.lib // link against aknskins.lib
Add two include files in SkinExampleContainer.h
 
Code:
#include <AknsDrawUtils.h>// add this inlcude file skin
#include <AknsBasicBackgroundControlContext.h> //add this inlcude file skin
 
Enabling skins in AppUi

Code:
/* In SkinExampleAppUi.cpp */
void CSkinExampleAppUi::ConstructL()
    {
    BaseConstructL( EAknEnableSkin );//Construct a enalbe skin
    .....
    }

new and delete a MAknsControlContext class in Container class

Add a MAknsControlContext class in container class

Code:
/* In skinExampleContainer.h */
class CSkinExampleContainer : public CCoeControl, MCoeControlObserver
{
 ....  
  private:
  MAknsControlContext* iBackGround; // for skins support 
}
 
/* In SkinExapleContainer.cpp */ 
void CSkinExampleContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();
 
    iLabel = new (ELeave) CEikLabel;
    iLabel->SetContainerWindowL( *this );
    iLabel->SetTextL( _L("Skin Example") );
 
    SetRect(aRect);
    iBackGround = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, Rect(), EFalse );// new a background
    ActivateL();
    }
 
Delete iBackGroud

Code:
// Destructor
CSkinExampleContainer::~CSkinExampleContainer()
    {
   .....
 delete iBackGround;
    }
 
Draw the background bitmap using Skin library
Code:
/* In SkinExapleContainer.cpp */
void CSkinExampleContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
 // draw background
 MAknsSkinInstance* skin = AknsUtils::SkinInstance();//new
 MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );//new
    AknsDrawUtils::Background( skin, cc, this, gc, aRect );//new
    }
 
MObjectProvider Chains
MObjectProvider interface can be used to make object instances available to child controls.
MopSupplyObject returns a pointer based on the given UID.
 
Code:
/* In SkinExapleContainer.cpp */
TTypeUid::Ptr CSkinExampleContainer::MopSupplyObject(TTypeUid aId)
    {
    if(aId.iUid == MAknsControlContext::ETypeId && iBackGround)
        {
        return MAknsControlContext::SupplyMopObject( aId, iBackGround);
        }
 
    return CCoeControl::MopSupplyObject( aId );
    }
Note: If you want to get the source code about this article ,plz contact me.
现在出现如下错误: AndroidManifest.xml文件的错误: 错误处代码:android:name=".MyApplication" 错误信息:Class referenced in the manifest, `com.example.floatingsearchapp.MyApplication`, was not found in the project or the libraries 错误信息:Unresolved class 'MyApplication' 错误处代码:<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> 错误信息:READ_EXTERNAL_STORAGE is deprecated (and is not granted) when targeting Android 13+. If you need to query or interact with MediaStore or media files on the shared storage, you should instead use one or more new storage permissions: `READ_MEDIA_IMAGES`, `READ_MEDIA_VIDEO` or `READ_MEDIA_AUDIO`. 错误处代码:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 错误信息:WRITE_EXTERNAL_STORAGE is deprecated (and is not granted) when targeting Android 13+. If you need to write to shared storage, use the `MediaStore.createWriteRequest` intent. MainActivity.kt文件的错误: 错误处代码:startActivityForResult(intent, 100) 错误信息:<html>'startActivityForResult(Intent, Int): Unit' is deprecated. This method has been deprecated in favor of using the Activity Result API<br/>which brings increased type safety via an {@link ActivityResultContract} and the prebuilt<br/>contracts for common intents available in<br/>{@link androidx.activity.result.contract.ActivityResultContracts}, provides hooks for<br/>testing, and allow receiving results in separate, testable classes independent from your<br/>activity. Use<br/>{@link #registerForActivityResult(ActivityResultContract, ActivityResultCallback)}<br/>passing in a {@link StartActivityForResult} object for the {@link ActivityResultContract}.
06-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值