HarmonyOS/OpenHarmony-ArkTS基于API9元服务开发快速入门

一、创建项目

二、创建卡片

三、添加资源

四、具体代码

复制代码
@Entry
@Component
struct WidgetNewCard {
  /*
   * The title.
   */
  readonly TITLE: string = 'harmonyOs';
  readonly CONTEXT: string = '技术构建万物智联';

  /*
   * The action type.
   */
  readonly ACTION_TYPE: string = 'router';

  /*
   * The ability name.
   */
  readonly ABILITY_NAME: string = 'EntryAbility';

  /*
   * The message.
   */
  readonly MESSAGE: string = 'add detail';

  /*
   * The with percentage setting.
   */
  readonly FULL_WIDTH_PERCENT: string = '100%';

  /*
   * The height percentage setting.
   */
  readonly FULL_HEIGHT_PERCENT: string = '100%';

  build() {
    Row() {
      Column() {
        Text(this.TITLE)
          .fontSize(14)
          .fontColor(0xFEFEFE)
          .fontWeight(600)
        Text(this.CONTEXT)
          .fontSize(14)
          .fontColor(0xFEFEFE)
          .fontWeight(600)
      }
      .width(this.FULL_WIDTH_PERCENT)
    }
    .backgroundImage($r("app.media.new_bg"))
    .backgroundImageSize(ImageSize.Cover)
    .height(this.FULL_HEIGHT_PERCENT)
    .onClick(() => {
      postCardAction(this, {
        "action": this.ACTION_TYPE,
        "abilityName": this.ABILITY_NAME,
        "params": {
          "message": this.MESSAGE
        }
      });
    })
  }
}

五、运行案例

六、案例卡片效果

七、代码地址

(HarmonyOSAPP开发相关组件: 深圳市蛟龙腾飞网络科技有限公司 - Gitee.com)

相关推荐
贾伟康2 小时前
【化学实验室|04】HarmonyOS ArkTS 场景选择器实战:让 13 个离线实验的入口、筛选和返回路径保持一致
harmonyos·arkts·canvas·arkui·化学实验
特立独行的猫a2 小时前
仓颉语言GUI开发实战:用仓颉写串口/网络二合一调试助手
网络·ui·gui·harmonyos·tauri·仓颉
hqzing12 小时前
把 glibc 移植到鸿蒙 PC 上:它能用来做什么
华为·harmonyos
OH_TPC17 小时前
HarmonyOS APP开发---“习惯猫“习惯打卡App,需要用到这个库
华为·harmonyos·鸿蒙
熊猫钓鱼>_>20 小时前
开源鸿蒙平台 KMP 三方库 kotlin-csv 适配全流程:从编码假设到沙箱真机互通验证
开发语言·人工智能·华为·kotlin·harmonyos·鸿蒙
马剑威(威哥爱编程)1 天前
【共创稿事节】HarmonyOS 7 Agent 开发实战 09:Agent 测试评测集
华为·harmonyos
威哥爱编程1 天前
HarmonyOS 7 Agent 开发实战 04:云端 RAG 搭企业私有知识库问答
agent·harmonyos
威哥爱编程1 天前
HarmonyOS 7 Agent 开发实战 05:流式输出做打字机对话
agent·harmonyos
donk13141 天前
React Native for OpenHarmony 实战:三方库 react-native-circular-action-menu 的鸿蒙化适配指南
javascript·分布式·react native·react.js·wpf·harmonyos