本文主要介绍了微信小程序tabbar用法,结合实例形式详细分析了微信小程序中tabbar的功能、配置项使用方法与操作注意事项,希望能帮助到大家。
1、效果展示

2、原理:在app.json中配置tabBar属性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | {
"pages" : [
"index" ,
"picDisplay"
],
"window" : {
"navigationBarBackgroundColor" : "#ffffff" ,
"navigationBarTextStyle" : "black" ,
"navigationBarTitleText" : "首页" ,
"backgroundColor" : "#eeeeee" ,
"backgroundTextStyle" : "light" ,
"enablePullDownRefresh" : false
},
"tabBar" : {
"color" : "#666666" ,
"selectedColor" : "#06bd04" ,
"list" : [{
"pagePath" : "index" ,
"text" : "首页" ,
"iconPath" : "images/index.png" ,
"selectedIconPath" : "images/indexHL.png"
},{
"pagePath" : "picDisplay" ,
"text" : "图片展示" ,
"iconPath" : "images/picDisplay.png" ,
"selectedIconPath" : "images/picDisplayHL.png"
}]
}
}
|
3、关键代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | "tabBar" : {
"color" : "#666666" ,
"selectedColor" : "#06bd04" ,
"list" : [{
"pagePath" : "index" ,
"text" : "首页" ,
"iconPath" : "images/index.png" ,
"selectedIconPath" : "images/indexHL.png"
},{
"pagePath" : "picDisplay" ,
"text" : "图片展示" ,
"iconPath" : "images/picDisplay.png" ,
"selectedIconPath" : "images/picDisplayHL.png"
}]
}
|
4、操作方法
新建一个项目,打开app.json文件,将关键代码复制到"window":{},后面,注意window的大括号前加逗号,如下图

配置tabBar属性值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | "tabBar" : {
"color" : "#666666" ,
"selectedColor" : "#06bd04" ,
"list" : [{
"pagePath" : "index" ,
"text" : "首页" ,
"iconPath" : "images/index.png" ,
"selectedIconPath" : "images/indexHL.png"
},{
"pagePath" : "picDisplay" ,
"text" : "图片展示" ,
"iconPath" : "images/picDisplay.png" ,
"selectedIconPath" : "images/picDisplayHL.png"
}]
}
|
tabBar的5种常用属性与配置说明:
1) color:未选择字体颜色
2) selectedColor:选择字体颜色
3) borderStyle:tabbar上方线的颜色white(仅支持白色和黑色)
4) backgroundColor:tabbar背景颜色
5) list:设置rab列表项(最少2个,最多5个tab)。
另外,list作为数组属性,其每一项又是一个对象,list可以设置4种属性:
① text:设置tab上的文字
② iconPath:设置tab处于未激活状态时显示的图片路径。
③ selectedIconPath:设置tab处于激活状态时的图片路径(iconPath与selectedIconPath图片大小限制都是40KB)
④ pagePath:设置触按tab时的跳转页面路径(该页面必须在pages中进行了配置)
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。