• openharmony容器组件之Badge


    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的颜色

    效果如图:

    代码:

    1. @Entry
    2. @Component
    3. struct BadgeT {
    4. @State counts: number = 1
    5. @State message: string = 'new'
    6. build() {
    7. Column() {
    8. Flex({ justifyContent: FlexAlign.SpaceAround }) {
    9. //显示消息数量,点击增加消息数量值
    10. Badge({
    11. count: this.counts,
    12. maxCount: 99,
    13. style: { color: 0xffffff, fontSize: 16, badgeSize: 20, badgeColor: Color.Red }
    14. }) {
    15. Button('message').onClick(() => {
    16. this.counts++
    17. }).width(100).height(50).backgroundColor(0x317aa)
    18. }.width(100).height(50)
    19. //显示消息在右侧上角,显示消息内容
    20. Badge({
    21. value: this.message,
    22. style: { color: 0xffffff, fontSize: 9, badgeSize: 20, badgeColor: Color.Blue } }) {
    23. Text('message')
    24. .width(80)
    25. .height(50)
    26. .fontSize(16)
    27. .lineHeight(37)
    28. .borderRadius(10)
    29. .textAlign(TextAlign.Center)
    30. .backgroundColor(0xf3f4ED)
    31. }.width(80).height(50)
    32. //显示消息圆点在右侧
    33. Badge({
    34. value: ' ',
    35. position: BadgePosition.Right, style: { badgeSize: 6, badgeColor: Color.Red } }) {
    36. Text("message")
    37. .width(90)
    38. .height(50)
    39. .fontSize(16)
    40. .lineHeight(37)
    41. .borderRadius(10)
    42. .textAlign(TextAlign.Center)
    43. .backgroundColor(0xf3f4ED)
    44. }.width(90).height(50)
    45. }
    46. }
    47. .width('100%')
    48. .height('100%')
    49. .margin({ top: 10 })
    50. }
    51. }

  • 相关阅读:
    vue学习---基于vue2中的vue指令、插槽、内置组件
    【Java 进阶篇】HTML 语义化标签详解
    Bugzilla的使用(用户管理篇)
    [软考中级]软件设计师-计算机网络
    第三类医疗器械经营许可证经营范围
    14条最佳JavaScript代码编写技巧
    人工智能1概论
    C# OpenCvSharp 去除文字中的线条
    SaulLM-7B: A pioneering Large Language Model for Law
    深度学习环境配置9——Ubuntu下的tensorflow-gpu==2.4.0环境配置
  • 原文地址:https://blog.csdn.net/lplj717/article/details/126242099