用来显示或者提示一些基本信息,或进行一些基本操作,不能使用重逻辑
新建:1、在ets目录上右击;2、选择Service Widget;3、Dynamic Widget
其中Static Widget,只能做静态页面,不能做数据交互
Dynamic Widget可以做动态数据,及事件处理
在entry的model.json5中,
"extensionAbilities": [
{
"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"
}
]
}
]
就是的ability,在这个ability上,就是卡片
在EntryFormAbility中,最主要的方法:onAddForm(),就是做主要的逻辑处理
在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": "2*2",
"supportDimensions": [
"2*2",
"2*4"
]
}
]
}
卡片可以选择2*2和2*4