版权声明:欢迎转载,可Chat交流,写博不易请标明出处: https://blog.csdn.net/JackJia2015/article/details/86589445
效果展示
wx.showTabBarRedDot(Object object)
显示 tabBar 某一项的右上角的红点
wx.showTabBarRedDot属性
wx.hideTabBarRedDot(Object object)
隐藏 tabBar 某一项的右上角的红点
wx.hideTabBarRedDot属性
wx.showTabBar(Object object)
显示 tabBar
wx.showTabBar属性
wx.hideTabBar(Object object)
显示 tabBar
wx.hideTabBar属性
wx.setTabBarStyle(Object object)
动态设置 tabBar 的整体样式
wx.setTabBarStyle属性
wx.setTabBarItem(Object object)
动态设置 tabBar 某一项的内容
wx.setTabBarItem属性
wx.setTabBarBadge(Object object)
为 tabBar 某一项的右上角添加文本
wx.setTabBarBadge属性
wx.removeTabBarBadge(Object object)
为 tabBar 某一项的右上角添加文本
wx.removeTabBarBadge属性
示例:
效果展示
代码
首先照两张图片,在最外层创建images文件夹拖入图片
然后在App.json里设置tabbar
App.json
{
"pages":[
"pages/index1/index1",
"pages/index2/index2",
"pages/index3/index3",
"pages/index4/index4",
"pages/logs/logs"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#000",
"navigationBarTitleText": "导航栏",
"navigationBarTextStyle":"white"
},
"tabBar": {
"list": [{
"pagePath": "pages/index1/index1",
"text": "页面1",
"iconPath": "images/index.png",
"selectedIconPath": "images/index.png"
},{
"pagePath": "pages/index2/index2",
"text": "页面2",
"iconPath": "images/index.png",
"selectedIconPath": "images/index.png"
},{
"pagePath": "pages/index3/index3",
"text": "页面3",
"iconPath": "images/index.png",
"selectedIconPath": "images/index.png"
},{
"pagePath": "pages/index4/index4",
"text": "页面4",
"iconPath": "images/index.png",
"selectedIconPath": "images/index.png"
}]
}
}
index1.wxml
<!--pages/index1/index1.wxml-->
<button bindtap="btnClick1" type="primary">显示 tabBar 的页面1的右上角的红点</button>
<button bindtap="btnClick2" type="primary">隐藏 tabBar 的页面1的右上角的红点</button>
<button bindtap="btnClick3" type="primary">为 tabBar 右上角添加文本</button>
<button bindtap="btnClick4" type="primary">移除 tabBar 右上角的文本</button>
<button bindtap="btnClick5" type="primary">隐藏 tabBar</button>
<button bindtap="btnClick6" type="primary">显示 tabBar</button>
<button bindtap="btnClick7" type="primary">动态改变 tabBar 内容</button>
<button bindtap="btnClick8" type="primary">动态改变 tabBar 图标文字颜色</button>
index1.wxss
/* pages/index1/index1.wxss */
page{
background-color: lemonchiffon
}
button{
margin: 20rpx;
}
index1.js
// pages/index1/index1.js
/*
(1)wx.showTabBarRedDot 显示tabBar 某一项的右上角的红点
index:0 abBar 的哪一项,从左边算起
(2)wx.hideTabBarRedDot 显示tabBar 某一项的右上角的红点
index:0 abBar 的哪一项,从左边算起
(3)wx.showTabBar显示 tabBar
animation:false 否 是否需要动画效果
(4)wx.hideTabBar隐藏 tabBar
animation:false 否 是否需要动画效果
(5)wx.setTabBarItem 动态设置 tabBar 某一项的内容
index tabBar 的哪一项,从左边算起
text tab 上的按钮文字
iconPath 图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片
selectedIconPath 选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效
(6)wx.setTabBarStyle动态设置 tabBar 的整体样式
color tab 上的文字默认颜色,HexColor
selectedColor tab 上的文字选中时的颜色,HexColor
backgroundColor tab 的背景色,HexColor
borderStyle tabBar上边框的颜色, 仅支持 black/white
(7)wx.setTabBarBadge 为 tabBar 某一项的右上角添加文本
index tabBar 的哪一项,从左边算起
text 显示的文本,超过 4 个字符则显示成 ...
(8)wx.removeTabBarBadge 移除 tabBar 某一项右上角的文本
index tabBar 的哪一项,从左边算起
*/
Page({
data: {
},
btnClick1: function (options) {
wx.showTabBarRedDot({
index: 0,
})
},
btnClick2: function (options) {
wx.hideTabBarRedDot({
index: 0,
})
},
btnClick3: function (options) {
wx.setTabBarBadge({
index: 0,
text: '99'
})
},
btnClick4: function (options) {
wx.removeTabBarBadge({
index: 0,
})
},
btnClick5: function (options) {
wx.hideTabBar({
animation: true //是否需要动画效果
})
},
btnClick6: function (options) {
wx.showTabBar({
animation: true
})
},
btnClick7: function (options) {
wx.setTabBarItem({
index: 0,
text: '改变',
iconPath: 'images/index1.png',
selectedIconPath: 'images/index1.png'
})
},
btnClick8: function (options) {
wx.setTabBarStyle({
color: '#FF0000',
selectedColor: '#00FF00',
backgroundColor: '#0000FF',
borderStyle: 'white'
})
},
onLoad: function (options) {
}
})