hm_common_title_bar
OpenHarmony三方库中心仓:https://ohpm.openharmony.cn/#/cn/detail/common_title_bar
介绍
一款通用标题栏,支持高度自定义,可设置沉浸式状态,正常状态下为:左侧返回、居中标题,左中右均可自定义视图。
软件架构
Harmony next版本,兼容API12
效果图
安装教程
- ohpm install common_title_bar
使用说明
- 引入仓库
- 设置全局属性:状态栏高度、是否全面屏、标题栏高度、标题栏颜色等(可忽略,使用默认配置)
基础使用:
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({