鸿蒙OS 5 - 新闻应用 - 日历账户管理器
1 分•作者: zhousg•6 个月前
HarmonyOS 5 新闻应用日历账户管理实现
摘要
本文介绍了 HarmonyOS 5.0 新闻应用中日历账户管理功能的实现。该功能包括用于添加特定类型日历账户的按钮,以及用于删除日历账户的构建器。使用 ArkTS 语言实现账户的添加和删除操作。
1. 实现账户添加按钮组件
```
Column({ space: 15 }){
Button('添加体育新闻账户')
.onClick(async () => {
await this.addAccount('体育新闻', '#006699')
this.list = await this.calendarMgr.getAllCalendars()
})
Button('添加世界新闻账户')
.onClick(async () => {
await this.addAccount('世界新闻', '#ffaa00')
this.list = await this.calendarMgr.getAllCalendars()
})
}
.margin(15)
```
2. 实现账户删除构建器
```
@Builder
DeleteBuilder (calendar: calendarManager.Calendar) {
Text('删除')
.fontSize(24)
.width(120)
.textAlign(TextAlign.Center)
.height('100%')
.onClick(async () => {
await this.calendarMgr.deleteCalendar(calendar)
this.list = await this.calendarMgr.getAllCalendars()
})
}
```
查看原文
HarmonyOS 5 News App Calendar Account Management Implementation
Abstract
This article introduces the implementation of the calendar account management function in the HarmonyOS 5.0 news application. It includes buttons for adding specific types of calendar accounts and a builder for deleting calendar accounts. The ArkTS language is used to implement the account addition and deletion operations.<p>1. Implement the Account Addition Button Component
Column({ space: 15 }){
Button('Add Sports News Account')
.onClick(async () => {
await this.addAccount('Sports News', '#006699')
this.list = await this.calendarMgr.getAllCalendars()
})
Button('Add World News Account')
.onClick(async () => {
await this.addAccount('World News', '#ffaa00')
this.list = await this.calendarMgr.getAllCalendars()
})
}
.margin(15)
2. Implement the Account Deletion Builder
@Builder
DeleteBuilder (calendar: calendarManager.Calendar) {
Text('Delete')
.fontSize(24)
.width(120)
.textAlign(TextAlign.Center)
.height('100%')
.onClick(async () => {
await this.calendarMgr.deleteCalendar(calendar)
this.list = await this.calendarMgr.getAllCalendars()
})
}