一招快速实现自定义快应用titlebar

背景

快应用中系统自带的titleBar是默认在左边的,且是无法进行自定义的,开发者在开发过程中遇到的需求是显示在顶部的正中间,而不是左边。本文旨在帮助开发者实现自定义titleBar。

实现步骤

自定义titleBar实现分为两步。

1、manifest.json文件里设为titleBar属性设置为false,隐藏系统自带的titeBar。  

"display": {
    "titleBar": false,
    "pages": {
      "Hello": {
        "statusBarBackgroundColor": "#0faeff"
      }
    }
  }

2、实现自定义titleBar,使用一个text组件,并使其居中显示即可。

<template>
  <!-- Only one root node is allowed in template. -->
  <div class="container">
    <text class="txt">titlebar</text>
    <div class="label">
      <text style="font-size: 60px">this is test page</text>
    </div>
  </div>
</template>
<style>
  .container {
    flex-direction: column;
    align-items: center;
  }
  .txt {
    font-size60px;
    color#00ced1;
    margin-top15px;
  }
  .label {
    flex-direction: column;
    justify-content: center;
    width100%;
    height100%;
  }
</style>
<script>
  module.exports = {
    data: {
      status1
    },
    onInit() {
    },
    onShow(options) {
      '// Do something when show.'
    },
  }
</script>

效果图:

cke_9686.png

欲了解更多详情,请参见快应用manifest文件介绍:

https://developer.huawei.com/consumer/cn/doc/development/quickApp-Guides/quickapp-develop-deeplink

posted @   华为开发者论坛  阅读(136)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2021-06-23 IAP商品修改和数据获取,一文带你全部搞懂
2021-06-23 华为支付切换到某国家后支付报错60003
点击右上角即可分享
微信分享提示