微信小程序自定义导航栏

微信小程序须要自定义导航栏,特别是左上角的自定义设置,能够设置返回按钮,菜单按钮,配置以下:css

一、在app.json的window属性中增长:html

navigationStyle:custom  

顶部导航栏就会消失,只保留右上角胶囊状的按钮。json

 

二、为了兼容适配全部机型,包括刘海屏,须要动态获取高度,并在app.js中设置:小程序

App({
    globalData: {
      statusBarHeight:wx.getSystemInfoSync()['statusBarHeight']
    }
})

三、在wxml页面自定义导航内容微信小程序

<view class="custom flex_center" style="padding-top:{{statusBarHeight}}px">
  <text>demo</text>
</view>
<view class="empty_custom" style="padding-top:{{statusBarHeight}}px"></view>

四、在app.css中设置统同样式:微信

.custom{
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  height: 45px;
  background: #f2f2f2;
  z-index: 999;
}
.custom text{
  color: #fff;
  font-size: 34rpx;
  font-weight: 500;
  max-width: 280rpx;
}
.empty_custom{
  height: 45px;
  width: 100%;
}

五、在js文件中设置高度app

Page({
    data:{
        statusBarHeight: app.globalData.statusBarHeight
    }
})
相关文章
相关标签/搜索