微信小程序tabBar是在全局app.json文件里面配置的,小程序tabBar配置代码注解说明。
{ "pages":[ "pages/index/index", "pages/detail/detail" ], "window":{ "navigationBarTitleText": "TabBar", "navigationBarBackgroundColor": "#F60", "navigationBarTextStyle": "white" }, //tabBar注意是B是大写,有朋友提问运行时tab没出现,检查是不是这里手误 "tabBar":{ //文档指出color是必填项,其实可为空,不重写color就是深灰,样式更统一 "color": "#ddd", //同样,文档指出selectedColor是必填项,不过selectedColor有必要重写,区分当前项与普通项 "selectedColor": "#3cc51f", //同样,文档指出color是必填项,其实可为空,不重写backgroundColor就是浅灰,样式更统一。 "backgroundColor": "#fff", //borderStyle,不写默认就是黑,那就黑好了,white的话,会少一条分隔线,跟页面混在一起了 "borderStyle":"black", "list":[{ "pagePath":"pages/index/index", //iconPath图标是非必填,只是tab栏会变矮,自然selectedIconPath也可不写 "iconPath":"image/icon_API.png", "selectedIconPath":"image/icon_API_HL.png", "text":"index" },{ "pagePath":"pages/detail/detail", "iconPath":"image/icon_component.png", "selectedIconPath":"image/icon_component_HL.png", "text":"detail" }] } }
参数说明
如果我们的小程序是一个多 tab 应用(客户端窗口的底部有tab栏可以切换页面),那么我们可以通过 tabBar 配置项指定 tab 栏的表现,以及 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 |
selectedIconPath | String | 是 | 选中时的图片路径,icon 大小限制为40kb |
相关专题
API
2022-06-15 12API是开发中必备知识点,合理的应用API可以大大节省开发成本,为您整理收集了包含API接口的信息,包含API接口,API代码,API源码,助你更快的学习使用API技术....
- 2022蓝奏云PHP解析API接口源代码 [2022-06-15]
- 分享两款高清QQ头像API调用接口 [2022-06-06]
- 最新蓝奏云直连解析API接口php代码 [2022-05-05]
- 基于百度API文字转语音Python示例代码 [2022-05-04]
- 网站访客大数据腾讯地图API展示源码 [2022-05-04]