文档开发者中心
我的
|

HarmonyOS 5

鸿蒙应用里创建的卡片无法添加到桌面上

50
鸿蒙应用里创建的卡片无法添加到桌面上,只是换到了另一页,空空如也
点赞
收藏
回复
2
分享
举报
浏览266 发布于2024-11-06 02:58陕西
全部评论
最多点赞
最新发布
最早发布
收起
自动换行
深色代码主题
复制
{
  "name": "EntryFormAbility",
  "srcEntry": "./ets/entryformability/EntryFormAbility.ets",
  "description": "$string:EntryFormAbility_desc",
  "icon": "$media:layered_image",
  "label": "$string:EntryFormAbility_label",
  "startWindowIcon": "$media:startIcon",
  "startWindowBackground": "$color:start_window_background"
}这玩意儿给我添加到extensionAbilities外面去了....解决了,大佬点醒了我.谢谢大佬.抱拳了
2楼回复于2024-11-08 03:02 来自陕西

双指捏合屏幕会出现配置卡片的应用提示

如果你的项目没有按照下方的操作指导,可以自查一下

右键entry新建动态服务卡片

src/main/ets/entryformability/EntryFormAbility.ets这个路径下会产生卡片启动文件

src/main/resources/base/profile/form_config.json这个路径会产生卡片配置文件

收起
自动换行
深色代码主题
复制
{
  "forms": [
    {
      "name": "widget",
      "displayName": "$string:widget_display_name",
      "description": "$string:widget_desc",
      "src": "./ets/widget/pages/WidgetCard.ets",
      "uiSyntax": "arkts",
      "window": {
        "designWidth": 720,
        "autoDesignWidth": true
      },
      "colorMode": "auto",
      "isDynamic": true,
      "isDefault": true,
      "updateEnabled": false,
      "scheduledUpdateTime": "10:30",
      "updateDuration": 1,
      "defaultDimension": "1*2",
      "supportDimensions": [
        "1*2",
        "2*2",
        "2*4",
        "4*4",
        "6*4"
      ]
    }
  ]
}

src指向自己的卡片页面:

以我的随机双色球卡片为例

收起
自动换行
深色代码主题
复制
import { formProvider } from '@kit.FormKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { formInfo } from '@kit.FormKit';

@Entry
@Component
struct WidgetCard {
  @State x: number = 1
  @State y: number = 1
  @State genNum: number[] = []

  aboutToAppear(): void {
    this.genNum = this.generateDoubleColorBallNumbers()
  }

  build() {
    Row() {
      Row() {
        ForEach(this.genNum, (item: number, index: number) => {
          Text(item.toString())
            .fontSize(25)
            .fontColor(index === this.genNum.length - 1 ? Color.Blue : Color.Red)
        })
      }
      .width('100%')
      .height('50%')
      .border({ width: 1, color: Color.Orange })
      .justifyContent(FlexAlign.SpaceAround)
      .onClick(() => {
        this.x = 1.1
        this.y = 1.1
        this.genNum = this.generateDoubleColorBallNumbers()

      })
      .scale({ x: this.x, y: this.y })
      .animation({
        curve: Curve.EaseOut,
        playMode: PlayMode.AlternateReverse,
        duration: 200,
        onFinish: () => {
          this.x = 1
          this.y = 1
        }
      })
    }
    .padding('10vp')
    .width('100%')
    .height('100%')
    .onClick(() => {
      postCardAction(this, {
        "action": 'router',
        "abilityName": 'EntryAbility',
        "params": {
          "message": 'router test'
        }
      });
    })
  }


  generateDoubleColorBallNumbers(): number[] {
    const redBalls: Set<number> = new Set(); // 使用Set确保红色球号的唯一性
    while (redBalls.size < 6) { // 生成6个不重复的红色球号,范围1-33
      const redBall = Math.floor(Math.random() * 33) + 1;
      redBalls.add(redBall);
    }
    const redNumbers = Array.from(redBalls).sort((a, b) => a - b); // 转换为数组并排序

    const blueBall = Math.floor(Math.random() * 16) + 1; // 生成蓝色球号,范围1-16

    return redNumbers.concat(blueBall);
  }
}

最后检查下module.json5中的extensionAbilities是否多了一个ability

收起
自动换行
深色代码主题
复制
{
        "name": "EntryFormAbility",
        "srcEntry": "./ets/entryformability/EntryFormAbility.ets",
        "label": "$string:EntryFormAbility_label",
        "description": "$string:EntryFormAbility_desc",
        "type": "form",
        "metadata": [
          {
            "name": "ohos.extension.form",
            "resource": "$profile:form_config"
          }
        ]
      }
展开全部
1楼回复于2024-11-07 12:49 来自广东
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要提问题

了解社区公约,与您携手共创和谐专业的开发者社区。