微信小程序須要自定義導航欄,特別是左上角的自定義設置,能夠設置返回按鈕,菜單按鈕,配置以下: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 } })