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)

相关推荐
勿念4362 小时前
在鸿蒙HarmonyOS 5中使用DevEco Studio实现指南针功能
华为·harmonyos
在人间耕耘3 小时前
unipp---HarmonyOS 应用开发实战
华为·harmonyos
libo_20253 小时前
语音交互设计:为HarmonyOS5应用添加多模态控制方案
harmonyos
kangyouwei3 小时前
鸿蒙开发:18-hilogtool命令的使用
前端·harmonyos
全栈若城4 小时前
105.[HarmonyOS NEXT 实战案例:新闻阅读应用] 高级篇 - 高级布局技巧与组件封装
harmonyos
zhanshuo4 小时前
弱网也不怕!鸿蒙分布式数据同步的4大“抗摔“秘籍,购物车实战解析
harmonyos
勿念4364 小时前
在鸿蒙HarmonyOS 5中使用DevEco Studio实现企业微信功能
harmonyos
Georgewu13 小时前
【HarmonyOS 5】鸿蒙中Stage模型与FA模型详解
harmonyos
颜颜yan_15 小时前
【HarmonyOS5】UIAbility组件生命周期详解:从创建到销毁的全景解析
架构·harmonyos·鸿蒙·鸿蒙系统