Harmony Next -- 通用标题栏:高度自定义,可设置沉浸式状态,正常状态下为:左侧返回、居中标题,左中右均可自定义视图。

hm_common_title_bar

OpenHarmony三方库中心仓:https://ohpm.openharmony.cn/#/cn/detail/common_title_bar

介绍

一款通用标题栏,支持高度自定义,可设置沉浸式状态,正常状态下为:左侧返回、居中标题,左中右均可自定义视图。

软件架构

Harmony next版本,兼容API12

效果图

在这里插入图片描述

安装教程
  1. ohpm install common_title_bar
使用说明
  1. 引入仓库
  2. 设置全局属性:状态栏高度、是否全面屏、标题栏高度、标题栏颜色等(可忽略,使用默认配置)

基础使用:

import { CommonTitleBar, TitleType } from '@ohos/commonTitleBar'
import { promptAction } from '@kit.ArkUI';

@Component
export struct TitlePage {
  /**
   * rightType: TitleType.IMAGE时,设置了rightMorePopupData: this.rightMorePopup
   * 则会显示气泡菜单弹窗:如微信扫一扫弹窗
   */
  @State rightMorePopup: MenuItemOptions[] = [
    {
      startIcon: $r('app.media.ic_edit'),
      content: "编辑资料",
    }, {
    startIcon: $r('app.media.ic_download'),
    content: "上传信息",
  }, {
    startIcon: $r('app.media.ic_upload'),
    content: "下载信息",
  }, {
    startIcon: $r('app.media.ic_scan'),
    content: "扫一扫",
  }
  ]

  /**
   * 左侧自定义视图
   */
  @Builder
  leftBuilder() {
    Row() {
      Image($r('app.media.ic_arrow_left'))
        .height(20)
      Text('返回')
        .onClick(() => {
          promptAction.showToast({
            message: "点击了左侧自定义视图",
            duration: 1500,
          })
        })
    }
  }

  /**
   * 右侧自定义视图
   */
  @Builder
  rightBuilder() {
    Row() {
      Text('更多')
        .onClick(() => {
          promptAction.showToast({
            message: "点击了右侧自定义视图",
            duration: 1500,
          })
        })
      Image($r('app.media.ic_more'))
        .height(20)
    }
  }

  /**
   * 居中自定义视图
   */
  @Builder
  centerBuilder() {
    Row() {
      Image($r('app.media.ic_arrow_left'))
        .height(20)
      Text('居中')
        .onClick(() => {
          promptAction.showToast({
            message: "点击了居中自定义视图",
            duration: 1500,
          })
        })
      Image($r('app.media.ic_more'))
        .height(20)
    }
  }

  build() {
    NavDestination() {
      Scroll() {
        Column() {
          CommonTitleBar({
            leftType: TitleType.NONE,
            centerType: TitleType.TEXT,
            centerText: "通用标题栏",
          })

          CommonTitleBar({
            isFullScreen: false,
            leftType: TitleType.TEXT,
            leftText: "返回",
            centerType: TitleType.TEXT,
            centerText: "非全面屏+左右文字",
            rightType: TitleType.TEXT,
            rightText: "更多",
          })

          /**
           * 左侧返回,右侧更多+气泡菜单
           */
          CommonTitleBar({
            isFullScreen: false,
            centerType: TitleType.TEXT,
            centerText: "左侧返回+右侧更多",
            rightType: TitleType.IMAGE,
            rightMorePopupData: this.rightMorePopup,
            rightOnClick: (menu, index) => {
              promptAction.showToast({
                message: menu?.content + '---' + index,
                duration: 1500,
              })
            }
          })

          CommonTitleBar({
            isFullScreen: false,
            centerType: TitleType.TEXT,
            centerText: "自定义点击事件",
            centerOnClick: (): void => {
              promptAction.showToast({
            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

PZR001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值