华为鸿蒙应用--封装通用标题栏:CommonTitleBar(鸿蒙工具)-ArkTs

注:该版本为API9,最新Next版本在这里:Harmony Next -- 通用标题栏:高度自定义,可设置沉浸式状态,正常状态下为:左侧返回、居中标题,左中右均可自定义视图。_鸿蒙 navdestination 标题居中-CSDN博客
0、效果图

自定义通用标题栏

支持左、中、右常规标题栏设置;

支持自定义视图;

支持搜索功能

一、CommTitleBar代码
import router from '@ohos.router';
import { Constants } from '../../constants/Constants';
import { StyleConstants } from '../../constants/StyleConstants'
import { toast } from '../../utils/ToastUtils';

@Component
export struct CommonTitleBar {
  @State titleBarHeight: number = 50; // 标题栏高度
  @State showBottomLine: boolean = true; //  是否显示标题栏底部的分割线
  titleBarColor: ResourceColor = '#f5f5f5'; // 标题栏颜色
  bottomLineColor: ResourceColor = "#DDDDDD"; // 标题栏分割线颜色

  @State leftType: number = Constants.TYPE_LEFT_IMAGE_VIEW; // 左侧视图类型:无|文字|按钮|自定义视图,默认显示返回按钮
  @State leftText: string = '左侧文字'; // 左侧文字leftType= textView有效
  @State leftMargin: number | string = 12; // 左侧间距
  leftTextColor: ResourceColor = "#000000"; // 左侧文字颜色
  @State leftTextSize: number | string = 16; // 左侧文字大小
  leftImageResource: string | PixelMap | Resource = $r('app.media.img_back_black'); // 左侧返回图片
  @BuilderParam leftCustomView: () => void = null; // 左侧自定义View
  onClickLeftText?: () => void; // 左侧文字点击事件
  onClickLeftImage?: () => void; // 左侧图片点击事件

  @State rightType: number = Constants.TYPE_RIGHT_NONE; // 右侧视图类型:无|文字|按钮|自定义视图,默认无视图
  @State rightText: string = '右侧文字'; // 右侧文字leftType= textView有效
  @State rightMargin: number | string = 12; // 右侧间距
  rightTextColor: ResourceColor = "#000000"; // 右侧文字颜色
  @State rightTextSize: number | string = 16; // 右侧文字大小
  rightImageResource: string | PixelMap | Resource = $r('app.media.img_back_black'); // 右侧图片
  @BuilderParam rightCustomView: () => void = null; // 右侧自定义View
  onClickRightText?: () => v
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

PZR001

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

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

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

打赏作者

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

抵扣说明:

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

余额充值