介紹
服務(wù)卡片的布局和使用,其中卡片內(nèi)容顯示使用了一次開發(fā),多端部署的能力實現(xiàn)多設(shè)備自適應(yīng)。
用到了卡片擴展模塊接口,[@ohos.app.form.FormExtensionAbility] 。
卡片信息和狀態(tài)等相關(guān)類型和枚舉接口,[@ohos.app.form.formInfo]。
卡片數(shù)據(jù)綁定的能力接口[@ohos.app.form.formBindingData]。
效果預(yù)覽
使用說明
長按示例應(yīng)用,等待出現(xiàn)服務(wù)卡片字樣,點擊后可左右滑動選擇需要的卡片尺寸,添加到屏幕。
更多鴻蒙開發(fā)應(yīng)用知識已更新[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]參考前往。
具體實現(xiàn)
1、在module.json5文件添加拓展能力,類型為卡片,并設(shè)置卡片入口srcEntrance和卡片元數(shù)據(jù)metadata。[源碼參考] 如果失效請?zhí)砑觤au123789是v直接拿取。
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"srcEntrance": "./ets/entryability/EntryAbility.ets",
"description": "$string:EntryAbility_desc",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
],
"extensionAbilities": [
{
"name": "EntryFormAbility",
"srcEntrance": "./ets/entryformability/EntryFormAbility.ets",
"label": "$string:EntryFormAbility_label",
"description": "$string:EntryFormAbility_desc",
"type": "form",
"metadata": [
{
"name": "ohos.extension.form",
"resource": "$profile:form_config"
}
]
}
]
}
}
例如:"metadata": [ { "name": "ohos.extension.form", "resource": "$profile:form_config" }。
2、初始化卡片:通過實現(xiàn)@ohos.app.form.FormExtensionAbility卡片操作類,在卡片對象首次被創(chuàng)建時,初始化卡片綁定數(shù)據(jù)為空,并將卡片狀態(tài)設(shè)置為就緒狀態(tài)READY。 例如:onCreate(){ formBindingData.createFormBindingData({}) onAcquireFormState(want) { return formInfo.FormState.READY }。
3、配置卡片:用js編寫相應(yīng)的卡片,將卡片配置到resources/base/profile/form_config, [源碼參考]
{
"forms": [
{
"name": "complex",
"description": "This is a service widget.",
"src": "./js/complex/pages/index/index",
"window": {
"designWidth": 720,
"autoDesignWidth": true
},
"colorMode": "auto",
"isDefault": true,
"updateEnabled": true,
"scheduledUpdateTime": "10:30",
"updateDuration": 1,
"defaultDimension": "2*2",
"supportDimensions": [
"2*2",
"4*4"
]
},
{
"name": "test",
"description": "This is a service widget.",
"src": "./js/test/pages/index/index",
"window": {
"designWidth": 720,
"autoDesignWidth": true
},
"colorMode": "auto",
"isDefault": false,
"updateEnabled": true,
"scheduledUpdateTime": "10:30",
"updateDuration": 1,
"defaultDimension": "2*2",
"supportDimensions": [
"2*2"
]
},
{
"name": "immersive",
"description": "This is a service widget.",
"src": "./js/immersive/pages/index/index",
"window": {
"designWidth": 720,
"autoDesignWidth": true
},
"colorMode": "auto",
"isDefault": false,
"updateEnabled": true,
"scheduledUpdateTime": "10:30",
"updateDuration": 1,
"defaultDimension": "2*2",
"supportDimensions": [
"2*2"
]
},
{
"name": "grid",
"description": "This is a service widget.",
"src": "./js/grid/pages/index/index",
"window": {
"designWidth": 720,
"autoDesignWidth": true
},
"colorMode": "auto",
"isDefault": false,
"updateEnabled": true,
"scheduledUpdateTime": "10:30",
"updateDuration": 1,
"defaultDimension": "2*2",
"supportDimensions": [
"2*2"
]
},
{
"name": "imgText",
"description": "This is a service widget.",
"src": "./js/imgText/pages/index/index",
"window": {
"designWidth": 720,
"autoDesignWidth": true
},
"colorMode": "auto",
"isDefault": false,
"updateEnabled": true,
"scheduledUpdateTime": "10:30",
"updateDuration": 1,
"defaultDimension": "2*2",
"supportDimensions": [
"2*2",
"2*4"
]
}
]
}
審核編輯 黃宇
-
HarmonyOS
+關(guān)注
關(guān)注
79文章
1983瀏覽量
30630 -
OpenHarmony
+關(guān)注
關(guān)注
25文章
3749瀏覽量
16660 -
鴻蒙OS
+關(guān)注
關(guān)注
0文章
190瀏覽量
4555
發(fā)布評論請先 登錄
相關(guān)推薦
鴻蒙OS開發(fā)實例:【手?jǐn)]服務(wù)卡片】
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>OS</b><b class='flag-5'>開發(fā)</b>實例:【手?jǐn)]<b class='flag-5'>服務(wù)</b><b class='flag-5'>卡片</b>】](https://file1.elecfans.com/web2/M00/C7/0B/wKgaomYFdeqAZW74ABvHzjRkbFM685.jpg)
鴻蒙OS開發(fā):【一次開發(fā),多端部署】應(yīng)用(自適應(yīng)布局)
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>OS</b><b class='flag-5'>開發(fā)</b>:【一次<b class='flag-5'>開發(fā)</b>,多端部署】應(yīng)用(<b class='flag-5'>自適應(yīng)</b>布局)](https://file1.elecfans.com/web2/M00/E6/FF/wKgaomZF_daADsVyACm1DJwF5FI239.jpg)
鴻蒙OS開發(fā):【一次開發(fā),多端部署】(多設(shè)備自適應(yīng)能力)實例
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>OS</b><b class='flag-5'>開發(fā)</b>:【一次<b class='flag-5'>開發(fā)</b>,多端部署】(<b class='flag-5'>多</b><b class='flag-5'>設(shè)備</b><b class='flag-5'>自適應(yīng)</b>能力)實例](https://file1.elecfans.com/web2/M00/E7/E3/wKgaomZKAH-AatXaAACU37E_f4c944.jpg)
鴻蒙OS開發(fā):【一次開發(fā),多端部署】(自適應(yīng)布局)
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>OS</b><b class='flag-5'>開發(fā)</b>:【一次<b class='flag-5'>開發(fā)</b>,多端部署】(<b class='flag-5'>自適應(yīng)</b>布局)](https://file1.elecfans.com/web2/M00/E6/FF/wKgaomZF_daADsVyACm1DJwF5FI239.jpg)
鴻蒙實戰(zhàn)項目開發(fā):【短信服務(wù)】
鴻蒙原生開發(fā)手記:01-元服務(wù)開發(fā)
鴻蒙os系統(tǒng)是什么意思 鴻蒙os系統(tǒng)有什么作用
木棉花:【資料匯集】服務(wù)卡片相關(guān)學(xué)習(xí)資料的匯總
《HarmonyOS原子化服務(wù)卡片原理與實戰(zhàn)》清華大學(xué)出版社李洋著
鴻蒙原生應(yīng)用開發(fā)-折疊屏、平板設(shè)備服務(wù)卡片適配
B站添加鴻蒙服務(wù)卡片教程
![B站添加<b class='flag-5'>鴻蒙</b><b class='flag-5'>服務(wù)</b><b class='flag-5'>卡片</b>教程](https://file.elecfans.com/web2/M00/0F/89/pYYBAGEUg5KAajF4AAAkBDfoaeI926.png)
華為開發(fā)者大會2021鴻蒙os在哪場
一款鴻蒙版的嗶哩嗶哩服務(wù)卡片應(yīng)用案例
鴻蒙OS開發(fā):【一次開發(fā),多端部署】(多設(shè)備自適應(yīng)能力)簡單介紹
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>OS</b><b class='flag-5'>開發(fā)</b>:【一次<b class='flag-5'>開發(fā)</b>,多端部署】(<b class='flag-5'>多</b><b class='flag-5'>設(shè)備</b><b class='flag-5'>自適應(yīng)</b>能力)簡單介紹](https://file1.elecfans.com/web2/M00/E7/E1/wKgaomZJ9OqAMlQ_AADD5r5qlN0794.jpg)
效率大升!AI賦能鴻蒙萬能卡片開發(fā)
![效率大升!AI賦能<b class='flag-5'>鴻蒙</b>萬能<b class='flag-5'>卡片</b><b class='flag-5'>開發(fā)</b>](https://file1.elecfans.com/web3/M00/05/CA/wKgZO2eEqKeALk_dAAAJvW2jUwc990.jpg)
評論