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)

相关推荐
高心星1 天前
鸿蒙5.0应用开发——V2装饰器@ObservedV2和@Trace的使用
harmonyos
城中的雾1 天前
HarmonyOS应用拉起系列(三):如何直接拉起腾讯/百度/高德地图进行导航
前端·javascript·harmonyos
程序员潘Sir1 天前
鸿蒙应用开发从入门到实战(七):ArkTS组件声明语法
harmonyos·鸿蒙
高心星2 天前
鸿蒙5.0项目开发——V2装饰器@Event的使用
harmonyos
ChinaDragon2 天前
HarmonyOS:创建ArkTS卡片
harmonyos
高心星2 天前
HarmonyOS 5.0应用开发——V2装饰器@once的使用
harmonyos
程序员潘Sir2 天前
鸿蒙应用开发从入门到实战(六):ArkTS声明式UI和组件化
harmonyos·鸿蒙
猫林老师2 天前
HarmonyOS数据持久化:Preferences轻量级存储实战
华为·harmonyos