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)

相关推荐
王嘉俊9252 小时前
HarmonyOS 微服务与 OpenHarmony 开发:构建模块化与开源生态应用
微服务·开源·harmonyos·arkts·开发·鸿蒙
半夜偷删你代码3 小时前
鸿蒙中传感器判断移动
华为·harmonyos
星释3 小时前
鸿蒙Flutter三方库适配指南-02.Flutter相关知识基础
flutter·华为·harmonyos
爱笑的眼睛113 小时前
HarmonyOS Canvas画布组件:高级图形绘制技术解析
华为·harmonyos
2501_919749033 小时前
鸿蒙:将Resource类型的image转成 image.PixelMap 类型
华为·harmonyos·鸿蒙
爱笑的眼睛113 小时前
HarmonyOS 环境光传感器自适应:构建智能光线感知应用
华为·harmonyos
猫林老师3 小时前
HarmonyOS物联网设备连接与管理实战
物联网·华为·harmonyos
二流小码农5 小时前
鸿蒙开发:web页面如何适配深色模式
android·ios·harmonyos
爱笑的眼睛115 小时前
HarmonyOS心率传感器数据采集:从原理到高级应用实践
华为·harmonyos
爱笑的眼睛119 小时前
HarmonyOS中Radio单选框组件的交互设计深度解析
华为·harmonyos