設置標題欄
標題欄window
在app.json文件里面,通過window對象里面的屬性進行設置
window
用於設置小程序的狀態欄、導航條、標題、窗口背景色。
| 屬性 | 類型 | 默認值 | 描述 | 最低版本 |
|---|---|---|---|---|
| navigationBarBackgroundColor | HexColor | #000000 | 導航欄背景顏色,如"#000000" | |
| navigationBarTextStyle | String | white | 導航欄標題顏色,僅支持 black/white | |
| navigationBarTitleText | String | 導航欄標題文字內容 | ||
| navigationStyle | String | default | 導航欄樣式,僅支持 default/custom。custom 模式可自定義導航欄,只保留右上角膠囊狀的按鈕 | 微信版本 6.6.0 |
| backgroundColor | HexColor | #ffffff | 窗口的背景色 | |
| backgroundTextStyle | String | dark | 下拉背景字體、loading 圖的樣式,僅支持 dark/light | |
| enablePullDownRefresh | Boolean | false | 是否開啟下拉刷新,詳見頁面相關事件處理函數 | |
| onReachBottomDistance | Number | 50 | 頁面上拉觸底事件觸發時距頁面底部距離,單位為px |
注:HexColor(十六進制顏色值),如"#ff00ff"
注:navigationStyle 只在 app.json 中生效。開啟 custom 后,低版本客戶端需要做好兼容。開發者工具基礎庫版本切到 1.7.0(不代表最低版本,只供調試用) 可方便切到舊視覺

運行:

設置導航欄
TabBar
如果我們的小程序是一個多 tab 應用(客戶端窗口的底部或頂部有 tab 欄可以切換頁面),那么我們可以通過 tabBar 配置項指定 tab 欄的表現,以及 tab 切換時顯示的對應頁面。
Tip: 通過頁面跳轉(wx.navigateTo)或者頁面重定向(wx.redirectTo)所到達的頁面,即使它是定義在 tabBar 配置中的頁面,也不會顯示底部的 tab 欄。
tabBar 是一個數組,只能配置最少2個、最多5個 tab,tab 按數組的順序排序。
屬性說明:
| 屬性 | 類型 | 必填 | 默認值 | 描述 |
|---|---|---|---|---|
| color | HexColor | 是 | tab 上的文字默認顏色 | |
| selectedColor | HexColor | 是 | tab 上的文字選中時的顏色 | |
| backgroundColor | HexColor | 是 | tab 的背景色 | |
| borderStyle | String | 否 | black | tabbar上邊框的顏色, 僅支持 black/white |
| list | Array | 是 | tab 的列表,詳見 list 屬性說明,最少2個、最多5個 tab | |
| position | String | 否 | bottom | 可選值 bottom、top |
其中 list 接受一個數組,數組中的每個項都是一個對象,其屬性值如下:
| 屬性 | 類型 | 必填 | 說明 |
|---|---|---|---|
| pagePath | String | 是 | 頁面路徑,必須在 pages 中先定義 |
| text | String | 是 | tab 上按鈕文字 |
| iconPath | String | 否 | 圖片路徑,icon 大小限制為40kb,建議尺寸為 81px * 81px,當 postion 為 top 時,此參數無效,不支持網絡圖片 |
| selectedIconPath | String | 否 | 選中時的圖片路徑,icon 大小限制為40kb,建議尺寸為 81px * 81px ,當 postion 為 top 時,此參數無效 |
示例:
app.json:

運行:

