小程序隐藏回退按钮,公用导航栏

回退以及 右上角胶囊丸 是小程序原生程序

// 先在页面json文件里如下配置,去掉小程序默认导航栏
  "navigationStyle": "custom",

去掉后,页面布局会整体靠上 需要 写一个全局共用组件去替代原标签栏

<view style="background:{{backColor}};height:{{autoheight}};position:relative;">
  <text style="color:{{textColor}};font-size:32rpx;position:absolute;bottom:{{textBottom}};left:0;right:0;text-align:center;line-height:1;font-weight:500;">{{title}}</text>
</view>
// distribution/assembly/navigateBar/navigateBar.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
  	// 导航背景颜色,默认 白色 
    backColor:{
      type: String,
      value: '#fff'
    },
    // 字体颜色默认黑色
    textColor: {
      type: String,
      value: '#000'
    },
    // 导航栏名字 默认为空
    title: {
      type: String,
      value: ''
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    autoheight: '47rpx'
  },

  /**
   * 组件的方法列表
   */
  methods: {

  },
  lifetimes: {
    attached: function () {
    // 因为不同手机 头部高度不同。要动态获取 高度 再赋予导航栏
      setTimeout(()=>{
        let obj = wx.getMenuButtonBoundingClientRect()
        this.setData({
          autoheight: (obj.bottom + 8) + "px",
          textBottom: (obj.height / 2 + 8 - 6) + "px",
        })
        wx.setBackgroundColor({
          backgroundColor: this.data.backColor, 
        })
        wx.setBackgroundColor({
          backgroundColorTop: this.data.backColor, // 顶部窗口的背景色为导航色
          backgroundColorBottom: '#f7f7f7', // 底部窗口的背景色为灰色
        })
      },100)
      
    },
  },
})

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值