https://developers.weixin.qq…. 全局配置 window navigationStyle 导航栏样式,仅支持以下值:

    • default 默认样式
    • custom 自定义导航栏,只保留右上角胶囊按钮

    小程序代码片段
    wechatide://minicode/AMdHRJm27G3I

    【小程序 】自定义顶部导航栏,添加背景图,自定义返回按钮 - 图1

    • 设置 navigationStyle

      • /app.json
        1. // /app.json
        2. {
        3. "pages": [
        4. "index/index",
        5. "index/main",
        6. "index/second",
        7. "index/halfPage"
        8. ],
        9. "window": {
        10. "backgroundTextStyle": "light",
        11. "navigationBarBackgroundColor": "#fff",
        12. "navigationBarTitleText": "WeChat",
        13. "navigationBarTextStyle": "black",
        14. "navigationStyle": "custom"
        15. }
        16. }
    • /index/second.wxml

    1. <!--index/second.wxml-->
    2. <view class="halfPage">
    3. <image mode="top" src="{{bg}}" class="image"/>
    4. <view class="arrow" bindtap="goback"></view>
    5. <view class="home"></view>
    6. </view>
    • /index/second.wxss
    1. /* index/second.wxss */
    2. .halfPage{
    3. display: flex;
    4. width: 100vw;
    5. height: 100vh;
    6. background-color: aliceblue;
    7. }
    8. .image{
    9. position: fixed;
    10. top: 0;
    11. left: 0;
    12. display: flex;
    13. width: 100vw;
    14. height: 30vh;
    15. overflow: hidden;
    16. }
    17. .arrow{
    18. position: fixed;
    19. left: 40rpx;
    20. top: 73rpx;
    21. display: flex;
    22. width: 35rpx;
    23. height:35rpx;
    24. border-left: 4rpx solid #6dc6ff;
    25. border-top: 4rpx solid #6dc6ff;
    26. transform: rotate(-45deg);
    27. }
    • /index/second.js
    1. // index/second.js
    2. Page({
    3. /**
    4. * 页面的初始数据
    5. */
    6. data: {
    7. bg:'/image/bg.jpg'
    8. },
    9. goback(){
    10. wx.navigateBack({delata:1})
    11. }
    12. })

    原文链接https://github.com/WangShuXian6/blog/issues/16