#星光计划1.0#HarmonyOS服务卡片开发-入口设置 原创

鸿蒙时代
发布于 2021-10-21 09:42
浏览
1收藏

一、简介
在原子化服务开发的过程中,新建的原子化服务四张卡片都是进入一个页面,那有什么方法让不同卡片进入不同入口,通过修改配置文件可以实现该需求。
二、方法
1、修改配置文件
“forms”: [
{
“jsComponentName”: “wkwidget”,
“isDefault”: false,
“scheduledUpdateTime”: “10:30”,
“defaultDimension”: “12",
“name”: “wkwidget”,
“description”: “”,
“colorMode”: “auto”,
“type”: “JS”,
“supportDimensions”: [
"1
2”
],
“updateEnabled”: true,
“updateDuration”: 1
},
{
“jsComponentName”: “xkwidget”,
“isDefault”: true,
“scheduledUpdateTime”: “10:30”,
“defaultDimension”: “22",
“name”: “xkwidget”,
“description”: “”,
“colorMode”: “auto”,
“type”: “JS”,
“supportDimensions”: [
"2
2”
],
“updateEnabled”: true,
“updateDuration”: 1
},
{
“jsComponentName”: “zkwidget”,
“isDefault”: false,
“scheduledUpdateTime”: “10:30”,
“defaultDimension”: “24",
“name”: “zkwidget”,
“description”: “”,
“colorMode”: “auto”,
“type”: “JS”,
“supportDimensions”: [
"2
4”
],
“updateEnabled”: true,
“updateDuration”: 1
},
{
“jsComponentName”: “dkwidget”,
“isDefault”: false,
“scheduledUpdateTime”: “10:30”,
“defaultDimension”: “44",
“name”: “dkwidget”,
“description”: “”,
“colorMode”: “auto”,
“type”: “JS”,
“supportDimensions”: [
"4
4”
],
“updateEnabled”: true,
“updateDuration”: 1
}
]

2、添加js文件
添加4个JS文件夹,分别对应4种卡片。

在这些文件夹下新建.jSON文件,用于指定卡片进入的页面ACE。
{
“data”: {},
“actions”: {
“routerEvent”: {
“action”: “router”,
“bundleName”: “com.fkxxskj.bailianCard”,
“abilityName”: “com.example.cardmodel.Ace.AboutAbility”
}
}
}
别忘了在html代码下应用该跳转。
<div class=“container” onclick=“routerEvent”>
3、新建AceAbility
建立4个ACE进行指定页面。

代码如下:
public class AboutAbility extends AceAbility {
@Override
public void onStart(Intent intent) {
setInstanceName(“default”);
setPageParams(“pages/index/about/about”,null);

    super.onStart(intent);

// this.getWindow().addFlags(WindowManager.LayoutConfig.MOD_STATUS_BAR);
this.setDisplayOrientation(AbilityInfo.DisplayOrientation.FOLLOWRECENT);
}

@Override
public void onStop() {
    super.onStop();
}

}
setInstanceName(“default”);
setPageParams(“pages/index/about/about”,null);
指定对应的页面。
【本文正在参与51CTO HarmonyOS技术社区创作者激励-星光计划1.0】
活动地址:星光计划1.0

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
标签
HarmonyOS服务卡片开发-入口设置.docx 24.73K 5次下载
1
收藏 1
回复
举报
回复
    相关推荐