<acronym id="s8ci2"><small id="s8ci2"></small></acronym>
<rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
<acronym id="s8ci2"></acronym>
<acronym id="s8ci2"><center id="s8ci2"></center></acronym>
0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

鴻蒙OS實戰開發:【多設備自適應服務卡片】

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-04-09 09:20 ? 次閱讀

介紹

服務卡片的布局和使用,其中卡片內容顯示使用了一次開發,多端部署的能力實現多設備自適應。
用到了卡片擴展模塊接口,[@ohos.app.form.FormExtensionAbility] 。

卡片信息和狀態等相關類型和枚舉接口,[@ohos.app.form.formInfo]。

卡片數據綁定的能力接口[@ohos.app.form.formBindingData]。

效果預覽

image.png

使用說明

長按示例應用,等待出現服務卡片字樣,點擊后可左右滑動選擇需要的卡片尺寸,添加到屏幕。

更多鴻蒙開發應用知識已更新[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]參考前往。

具體實現

搜狗高速瀏覽器截圖20240326151547.png
1、在module.json5文件添加拓展能力,類型為卡片,并設置卡片入口srcEntrance和卡片元數據metadata。[源碼參考] 如果失效請添加mau123789是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、初始化卡片:通過實現@ohos.app.form.FormExtensionAbility卡片操作類,在卡片對象首次被創建時,初始化卡片綁定數據為空,并將卡片狀態設置為就緒狀態READY。 例如:onCreate(){ formBindingData.createFormBindingData({}) onAcquireFormState(want) { return formInfo.FormState.READY }。
3、配置卡片:用js編寫相應的卡片,將卡片配置到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
    +關注

    關注

    79

    文章

    1874

    瀏覽量

    29334
  • OpenHarmony
    +關注

    關注

    23

    文章

    3376

    瀏覽量

    15194
  • 鴻蒙OS
    +關注

    關注

    0

    文章

    136

    瀏覽量

    4290
收藏 人收藏

    評論

    相關推薦

    鴻蒙OS開發實例:【手擼服務卡片

    服務卡片指導文檔位于“**開發/應用模型/Stage模型開發指導/Stage模型應用組件**”路徑下,說明其極其重要。本篇文章將分享實現服務
    的頭像 發表于 03-28 22:11 ?751次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>OS</b><b class='flag-5'>開發</b>實例:【手擼<b class='flag-5'>服務</b><b class='flag-5'>卡片</b>】

    鴻蒙實戰項目開發:【短信服務

    數據管理 電話服務 分布式應用開發 通知與窗口管理 多媒體技術 安全技能 任務管理 WebGL 國際化開發 應用測試 DFX面向未來設計 鴻蒙系統移植和裁剪定制 …… ? 《
    發表于 03-03 21:29

    鴻蒙OS適用的全場景到底什么意思?

    上,未來會有越來越多的智能設備使用開源的鴻蒙OS。華為消費者業務CEO余承東在介紹鴻蒙OS開發
    發表于 09-25 09:25

    鴻蒙os系統是什么意思 鴻蒙os系統有什么作用

    適配智慧屏,未來它將適配手機,平板,電腦,智能汽車,可穿戴設備終端設備。鴻蒙微內核是基于微內核的全場景分布式OS,可按需擴展,實現更廣泛
    發表于 12-17 11:34

    木棉花:【資料匯集】服務卡片相關學習資料的匯總

    前言木棉花組織是對鴻蒙學習的相關資源進行整合,由深圳大學學生團隊負責,長期更新。此次是將電子發燒友上的有關鴻蒙服務卡片學習相關資料進行匯總,以下是部分資料的展示,更多資料收納在我們組織
    發表于 08-12 23:48

    HarmonyOS卡片開發--服務卡片概述

    。 卡片提供方包含以下模塊:卡片服務:由卡片提供方開發者實現,開發者實現onCreateForm
    發表于 09-22 14:10

    《HarmonyOS原子化服務卡片原理與實戰》清華大學出版社李洋著

    對原子化服務未來發展的展望;繼續努力體驗與成長,持續奮斗。本書主要闡述鴻蒙操作系統( HarmonyOS )應用開發中全新的服務形式,原子化服務
    發表于 12-29 12:14

    鴻蒙 OS 應用開發初體驗

    的操作系統平臺和開發框架。HarmonyOS 的目標是實現跨設備的無縫協同和高性能。 DevEco Studio 對標 Android Studio,開發鴻蒙
    發表于 11-02 19:38

    鴻蒙原生應用開發-折疊屏、平板設備服務卡片適配

    一、設備卡片適配原則 為不同尺寸的卡片提供不同的功能 在卡片開發過程中請考慮適配不同尺寸的設備
    發表于 11-16 10:10

    LabVIEW開發自適應降噪ANC

    LabVIEW開發自適應降噪ANC 在許多情況下,信號很嘈雜,必須消除噪聲。自適應降噪(ANC)是可用于消除信號噪聲的主要實時方法之一??梢允褂肔abVIEW自適應濾濾器工具包來設計ANC應用程序
    發表于 11-30 19:38

    鴻蒙值得期待 鴻蒙OS系統適應計劃曝光

    幾天前,有人在微博上透露了鴻蒙OS在智能手機上的適應過程,主要是從手機上的芯片開始,涵蓋麒麟9000到麒麟710,引起了廣泛關注。 當然,除了華為的鴻蒙
    的頭像 發表于 10-11 10:51 ?1723次閱讀

    B站添加鴻蒙服務卡片教程

    ???????? 6 月 2 日鴻蒙發布,今年的六月已經被鴻蒙刷屏了。從安卓到鴻蒙,最直觀的變化應該就是服務卡片了。我也是在學習
    的頭像 發表于 08-12 10:07 ?2401次閱讀
    B站添加<b class='flag-5'>鴻蒙</b><b class='flag-5'>服務</b><b class='flag-5'>卡片</b>教程

    一款鴻蒙版的嗶哩嗶哩服務卡片應用案例

    介紹 這是一款純鴻蒙版的嗶哩嗶哩服務卡片應用。 6月2日鴻蒙發布,今年的六月已經被鴻蒙刷屏了。從安卓到
    發表于 04-07 09:42 ?0次下載

    用Java開發HarmonyOS服務卡片

    卡片服務:由卡片提供方開發者實現,開發者實現 onCreateForm、onUpdateForm 和 onDeleteForm 處理創建
    的頭像 發表于 04-26 11:04 ?1271次閱讀

    如何在OpenHarmony上開發服務卡片

    本篇文章我們將分享如何在 OpenHarmony 上開發服務卡片。
    的頭像 發表于 04-10 11:12 ?710次閱讀
    亚洲欧美日韩精品久久_久久精品AⅤ无码中文_日本中文字幕有码在线播放_亚洲视频高清不卡在线观看
    <acronym id="s8ci2"><small id="s8ci2"></small></acronym>
    <rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
    <acronym id="s8ci2"></acronym>
    <acronym id="s8ci2"><center id="s8ci2"></center></acronym>