小程序 导航配置
顶部导航配置
window用于设置小程序的状态栏、导航条、标题、窗口背景色。
//app.json
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#f0f", //导航背景色
"navigationBarTitleText": "首页", //导航文字
"navigationBarTextStyle": "white" //导航颜色,仅支持 black / white
}
编译结果如下:

底部导航配置
如果小程序是一个多 tab 应用(客户端窗口的底部或顶部有 tab 栏可以切换页面),可以通过 tabBar 配置项指定 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 | tabBar 的位置,仅支持 bottom / top
|
|
| custom | boolean | 否 | false | 自定义 tabBar,见详情 | 2.5.0 |
其中 list 接受一个数组,只能配置最少 2 个、最多 5 个 tab。tab 按数组的顺序排序,每个项都是一个对象,其属性值如下:
| 属性 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| pagePath | string | 是 | 页面路径,必须在 pages 中先定义 |
| text | string | 是 | tab 上按钮文字 |
| iconPath | string | 否 | 图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,不支持网络图片。 当 position 为 top 时,不显示 icon。
|
| selectedIconPath | string | 否 | 选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,不支持网络图片。 当 position 为 top 时,不显示 icon。
|
//app.json
"tabBar": {
"color": "#333", //文字颜色
"selectedColor": "#45A844", //选中文字颜色
"backgroundColor": "#ffffff", //导航背景色
"borderStyle": "white", //tabbar 上边框的颜色,仅支持 black / white
"list": [
{
"pagePath": "pages/index/index", //对应的页面
"iconPath": "images/shouye_default.png", //默认的图标
"selectedIconPath": "images/shouye.png", //选中高亮的图标
"text": "首页"
},
{
"pagePath": "pages/order/order",
"iconPath": "images/dingdan.png",
"selectedIconPath": "images/dingdan_check.png",
"text": "订单"
},
{
"pagePath": "pages/user/user",
"iconPath": "images/wode.png",
"selectedIconPath": "images/wode_check.png",
"text": "我的"
}
]
}
编译结果如下:

更多小程序全局配置 app.json>>>>>