基于HarmonyOS NEXT 5.0自定义增强版导航栏组件|鸿蒙ArkUI自定义标题栏
这段时间比较热门的莫过于华为推出的自主研发的面向全场景分布式操作系统HarmonyOS。
最新一直潜心学习鸿蒙os开发,于是基于HarmonyOS NEXT 5.0 API12 Release开发了一款自定义多功能导航条组件。
HMNavBar组件支持自定义返回键、标题/副标题、标题居中、背景色/背景图片/背景渐变色、标题颜色、搜索、右侧操作区等功能。
如下图:组件结构非常简单。
组件参数配置
@Component
export struct HMNavBar {
// 是否隐藏左侧的返回键
@Prop hideBackButton: boolean
// 标题(支持字符串|自定义组件)
@BuilderParam title: ResourceStr | CustomBuilder = BuilderFunction
// 副标题
@BuilderParam subtitle: ResourceStr | CustomBuilder = BuilderFunction
// 返回键图标
@Prop backButtonIcon: Resource | undefined = $r('sys.symbol.chevron_left')
// 返回键标题
@Prop backButtonTitle: ResourceStr
// 背景色
@Prop bgColor: ResourceColor = $r('sys.color.background_primary')
// 渐变背景色
@Prop bgLinearGradient: LinearGradient
// 图片背景
@Prop bgImage: ResourceStr | PixelMap
// 标题颜色
@Prop fontColor: ResourceColor
// 标题是否居中
@Prop centerTitle: boolean
// 右侧按钮区域
@BuilderParam actions: Array<ActionMenuItem> | CustomBuilder = BuilderFunction
// 导航条高度
@Prop navbarHeight: number = 56 // ...
}
调用方式非常简单易上手。
- 基础用法
HMNavBar({
backButtonIcon: $r('sys.symbol.arrow_left'),
title: '鸿蒙自定义导航栏',
subtitle: 'HarmonyOS Next 5.0自定义导航栏',
})
- 自定义返回图标/文字、标题、背景色、右键操作按钮
@Builder customImgTitle() {
Image('https://developer.huawei.com/allianceCmsResource/resource/HUAWEI_Developer_VUE/images/logo-developer-header.svg').height(24).objectFit(ImageFit.Contain)
} HMNavBar({
backButtonIcon: $r('sys.symbol.chevron_left'),
backButtonTitle: '返回',
title: this.customImgTitle,
subtitle: '鸿蒙5.0 api 12',
centerTitle: true,
bgColor: '#f3f6f9',
fontColor: '#0a59f7',
actions: [
{
icon: $r('app.media.app_icon'),
action: () => promptAction.showToast({ message: "show toast index 1" })
},
{
// icon: $r('sys.symbol.plus'),
label: '更多>',
color: '#bd43ff',
action: () => promptAction.showToast({ message: "show toast index 2" })
}
]
})
// 自定义渐变背景、背景图片、右侧操作区
HMNavBar({
hideBackButton: true,
title: 'HarmonyOS',
subtitle: 'harmonyos next 5.0 api 12',
bgLinearGradient: {
angle: 135,
colors: [['#42d392 ',0.2], ['#647eff',1]]
},
// bgImage: 'pages/assets/nav_bg.png',
// bgImage: 'https://developer.huawei.com/allianceCmsResource/resource/HUAWEI_Developer_VUE/images/1025-pc-banner.jpeg',
fontColor: '#fff',
actions: [
{
icon: 'https://developer.huawei.com/allianceCmsResource/resource/HUAWEI_Developer_VUE/images/yuanfuwuicon.png',
action: () => promptAction.showToast({ message: "show toast index 1" })
},
{
icon: 'https://developer.huawei.com/allianceCmsResource/resource/HUAWEI_Developer_VUE/images/0620logo4.png',
action: () => promptAction.showToast({ message: "show toast index 2" })
},
{
icon: $r('sys.symbol.person_crop_circle_fill_1'),
action: () => promptAction.showToast({ message: "show toast index 3" })
}
],
navbarHeight: 70
})
如上图:还支持自定义导航搜索功能。
HMNavBar({
title: this.customSearchTitle1,
actions: this.customSearchAction
}) HMNavBar({
hideBackButton: true,
title: this.customSearchTitle2,
bgColor: '#0051ff',
}) HMNavBar({
backButtonIcon: $r('sys.symbol.arrow_left'),
backButtonTitle: '鸿蒙',
title: this.customSearchTitle3,
bgColor: '#c543fd',
fontColor: '#fff',
actions: [
{
icon: $r('sys.symbol.mic_fill'),
action: () => promptAction.showToast({ ... })
}
]
})
HMNavBar导航组件布局结构如下。
build() {
Flex() {
// 左侧模块
Stack({ alignContent: Alignment.Start }) {
Flex(){
if(!this.hideBackButton) {
this.backBuilder()
}
if(!this.centerTitle) {
this.contentBuilder()
}
}
.height('100%')
}
.height('100%')
.layoutWeight(1) // 中间模块
if(this.centerTitle) {
Stack() {
this.contentBuilder()
}
.height('100%')
.layoutWeight(1)
} // 右键操作模块
Stack({ alignContent: Alignment.End }) {
this.actionBuilder()
}
.padding({ right: 16 })
.height('100%')
.layoutWeight(this.centerTitle ? 1 : 0)
}
.backgroundColor(this.bgColor)
.linearGradient(this.bgLinearGradient)
.backgroundImage(this.bgImage, ImageRepeat.NoRepeat).backgroundImageSize(ImageSize.FILL)
.height(this.navbarHeight)
.width('100%')
}
支持悬浮在背景图上面。
最后,附上几个最新研发的跨平台实例项目。
Tauri2.0+Vite5聊天室|vue3+tauri2+element-plus仿微信|tauri聊天应用
tauri2.0-admin桌面端后台系统|tauri2+vite5+element-plus管理后台EXE程序
Ok,今天的分享就到这里,希望以上的分享对大家有所帮助!
基于HarmonyOS NEXT 5.0自定义增强版导航栏组件|鸿蒙ArkUI自定义标题栏的更多相关文章
- 微信小程序自定义底部导航栏组件+跳转
微信小程序本来封装有底部导航栏,但对于想自定义样式和方法的开发者来说,这并不是很好. 参考链接:https://github.com/ljybill/miniprogram-utils/tree/ma ...
- 微信小程序自定义导航栏组件,完美适配所有手机,可实现各种功能和情况
背景 在做小程序时,关于默认导航栏,我们遇到了以下的问题: Android.IOS 手机对于页面 title 的展示不一致,安卓 title 的显示不居中 页面的 title 只支持纯文本级别的样式控 ...
- 微信小程序自定义导航栏组件
1.首先,要在json文件中设置为自定义的形式 "navigationStyle": "custom" 2.计算相关值 导航栏分为状态栏和标题栏,只要能算出每台 ...
- iOS:自定义工具栏、导航栏、标签栏
工具栏为UIToolBar,导航栏UINavigationBar,标签栏UITabBar.它们的样式基本上时差不多的,唯一的一点区别就是,工具栏一般需要自己去创建,然后添加到视图中,而导航栏和标签栏不 ...
- Apache Pulsar 2.6.1 版本正式发布:2.6.0 功能增强版,新增 OAuth2 支持
在 Apache Pulsar 2.6.0 版本发布后的 2 个月,2020 年 8 月 21 日,Apache Pulsar 2.6.1 版本正式发布! Apache Pulsar 2.6.1 修复 ...
- 更改系统相机UIImagePickerController导航栏的cancle为自定义按钮
有时候需要对系统相册里面的取消按钮进行自定义,并获取点击事件做一些操作,那么你可以这样做. 第一:实现navigationController代理 - (void)navigationControll ...
- iview修改tabbar实现小程序自定义中间圆形导航栏及多页面登录功能
emmm,用iview改了个自定义中间圆形的tabbar. 如下图所示, 重点,什么鬼是“多页面登录”? 例如:我现在要做一个功能,要说自己长得帅才能进去页面. 一个两个页面还好,但是我现在要每个页面 ...
- 解决ios7.0 以后自己定义导航栏左边button靠右的问题
1.自己定义button //左button UIButton *leftBtn = [[UIButton , , , )]; [leftBtn addTarget:self action:@sele ...
- 自定义iOS7导航栏背景,标题和返回按钮文字颜色
在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更改一下背景和颜色,代码会很简单,不需要很复杂的自定义View来替代leftBarItem 更改导航栏的背景和文字Col ...
- 【转】自定义iOS7导航栏背景,标题和返回按钮文字颜色 -- 不错不错!!
原文网址:http://blog.csdn.net/mad1989/article/details/41516743 在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更 ...
随机推荐
- bmp位图文件信息结构体
/************************************************* * * file name:BmpInfoStruct.c * author :momolyl@1 ...
- Linux下如何在程序中获取某个命令执行的结果?【附源码】
在工作中遇到一个问题,就是想获取某个函数执行之后打印的字符串信息. 这个功能应用场景挺多的, 特地整理了一下相关知识点分享给大家. 1. 使用临时文件 1) 使用shell的重定向 将命令输出重定向到 ...
- 折腾 Quickwit,Rust 编写的分布式搜索引擎(专为从对象存储中实现亚秒级搜索而设计)
什么是 Quickwit? Quickwit 是首个能在云端存储上直接执行复杂的搜索与分析查询的引擎,并且具有亚秒级延迟.它借助 Rust 语言和分离计算与存储的架构设计,旨在实现资源高效利用.易于操 ...
- 玄机蓝队靶场_应急响应_01:linux日志分析
个人感觉这个靶场主要考验对linux的命令的基础掌握,对日志路径的基本了解. 一:解题 (1)ssh连接靶场,先用命令lsb_release -a看看是什么系统.然后发现是Debian GNU/Lin ...
- Poetry 使用
Poetry 是当下热门的 Python 包管理器.Poetry 注重为项目提供完整的生命周期管理,包括构建.打包.发布和依赖管理.其使用 pyproject.toml 文件来管理项目的依赖和构建配置 ...
- Windows 包管理器
WinGet WinGet 是微软官方的软件管理器. 搜索 WinGet 包 常用命令 winget install <packaeg> # 安装包 winget uninstall &l ...
- LaTeX 书写函数
\[\text{text 模式} \] \[\mathrm{mathrm 模式} \] \[\textit{textit 模式} \] \[\operatorname{operatorname 模式} ...
- Consul初探-从安装到运行 【转】
目录 前言 下载二进制包 入门必学必记文档 启动 Consul 前言 伟人说过:实践是检验真理的唯一标准!经过上一篇的学习,我基本掌握了 Consul 的基本原理,接下来就是动手实践了:Consul ...
- 使用js闭包实现可取消的axios请求
在平常开发中,经常会遇到重复请求的情况,也许是因为网络问题,也许是因为接口问题等等,传统做法是客户端采用防抖来限制用户发送接口的频率,一般出个loading转圈圈的形式, 但是很少使用取消请求的做法, ...
- Angular 18+ 高级教程 – Memory leak, unsubscribe, onDestroy
何谓 Memory Leak? Angular 是 SPA (Single-page application) 框架,用来开发 SPA. SPA 最大的特点就是它不刷新页面,不刷新就容易造成 memo ...