当前位置:网站首页>openharmony容器组件之Badge
openharmony容器组件之Badge
2022-08-09 13:12:00 【lplj717】
Badge:新事件标记组件,在组件上提供事件信息展示能力
Badge(value: {count: number, position?: BadgePosition, maxCount?: number, style?: BadgeStyle})
count:设置提醒消息数
position:设置提示点显示位置(BadgePosition)
BadgePosition:RightTop(圆点显示在右上角),Right(圆点显示在右侧纵向居中),Left(圆点显示在左侧纵向居中)
maxCount:最大消息数,超过最大消息时仅显示maxCount+
style:Badge组件可设置样式,支持设置文本颜色、尺寸、圆点颜色和尺寸(BadgeStyle)
BadgeStyle:
color 文本颜色
fontSize 文本大小
badgeSize badge的大小
badgeColor badge的颜色
效果如图:
代码:
@Entry
@Component
struct BadgeT {
@State counts: number = 1
@State message: string = 'new'
build() {
Column() {
Flex({ justifyContent: FlexAlign.SpaceAround }) {
//显示消息数量,点击增加消息数量值
Badge({
count: this.counts,
maxCount: 99,
style: { color: 0xffffff, fontSize: 16, badgeSize: 20, badgeColor: Color.Red }
}) {
Button('message').onClick(() => {
this.counts++
}).width(100).height(50).backgroundColor(0x317aa)
}.width(100).height(50)
//显示消息在右侧上角,显示消息内容
Badge({
value: this.message,
style: { color: 0xffffff, fontSize: 9, badgeSize: 20, badgeColor: Color.Blue } }) {
Text('message')
.width(80)
.height(50)
.fontSize(16)
.lineHeight(37)
.borderRadius(10)
.textAlign(TextAlign.Center)
.backgroundColor(0xf3f4ED)
}.width(80).height(50)
//显示消息圆点在右侧
Badge({
value: ' ',
position: BadgePosition.Right, style: { badgeSize: 6, badgeColor: Color.Red } }) {
Text("message")
.width(90)
.height(50)
.fontSize(16)
.lineHeight(37)
.borderRadius(10)
.textAlign(TextAlign.Center)
.backgroundColor(0xf3f4ED)
}.width(90).height(50)
}
}
.width('100%')
.height('100%')
.margin({ top: 10 })
}
}
边栏推荐
猜你喜欢
随机推荐
机器学习web服务化实战:一次吐血的服务化之路 (转载非原创)
GET POST PUT DELETE request in GIN
Record the system calls and C library functions used in this project-2
企业公众号开通微信支付
01_iTween_第一天--小球抛物线
pytest 基础认知
FFmpeg相机花屏花图问题解决方法
处理JSON,fastjson、json-lib简单使用
RobotFramework 之 RF变量与标准库关键字使用
FFmpeg multimedia file processing (implementation of ffmpeg operation directory and list)
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 16 Assignment
【面试高频题】可逐步优化的链表高频题
RobotFramework 之 Evaluate
Q_06_02 类型模型
NC15 求二叉树的层序遍历
DCT变换与反变换
Q_06_03 表达式
RobotFramework 之 用户关键字
皮肤资料整理
问题系列-如何修改或更新localhost里的值