@Builder
tabBuilder(title: Resource, targetIndex: number, selectedImg?: Resource, normalImg?: Resource) {
Column({ space: 5 }) {
Badge({
count: 8,
maxCount: 99,
style: { badgeSize: 16, badgeColor: '#FA2A2D' },
position: BadgePosition.RightTop,
})
{
Image(this.currentIndex === targetIndex ? selectedImg : normalImg)
.size(this.currentIndex === targetIndex ? { width: 25, height: 25 } : { width: 23, height: 23 })
}
Text(title)
.fontColor(this.currentIndex === targetIndex ? '#ffb61e18' : '#6B6B6B')
.fontSize(this.currentIndex === targetIndex ? 16 : 14)
}
.width('100%')
.height(LayoutUtil.BottomTabsHeight)
.border({})
.justifyContent(FlexAlign.Center)
}
我设置了position: BadgePosition.RightTop, 但是UI上不太合适, 想往右再调整一下
Position作为入参,不支持设置百分比,当前仅支持系统预设的三个参数,参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-badge-V5\#badgeposition枚举说明
position可以设置自定义位置{ x: 40, y: -10},根据x,y设置偏移量,手动调整位置