Skip to content

qin.setTabBarItem(OBJECT) ​

动态设置 tabBar 某一项的内容

平台差异说明

H5微信小程序小红书小程序抖音小程序快手小程序
√√√√√

OBJECT 参数说明

属性类型默认值必填说明平台差异
indexnumber是tabBar 的哪一项,从左边算起
textString否tab 上的按钮文字
iconPathString否图片路径,icon 大小限制为 40kb ,建议尺寸为 81px * 81px ,当 position 为 top 时,此参数无效。微信小程序 2.7.0+、支付宝小程序支持网络图片,其他平台暂不支持网络图片
selectedIconPathString否选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px ,当 position 为 top 时,此参数无效
pagePathString否页面绝对路径,必须在 pages 中先定义,被替换掉的 pagePath 不会变成普通页面(仍然需要使用 qin.switchTab 跳转)H5
visibleBooleantrue否该项是否显示H5
iconfontObject否字体图标,优先级高于 iconPath
successFuntion否接口调用成功的回调函数
failFuntion否接口调用失败的回调函数
completeFuntion否接口调用结束的回调函数(调用成功、失败都会执行)

iconfont参数说明:

属性类型说明
textString字库 Unicode 码
selectedTextString选中后字库 Unicode 码
fontSizeString字体图标字号(px)
colorString字体图标颜色
selectedColorString字体图标选中颜色

示例代码

js
qin.setTabBarItem({
  index: 0,
  text: 'text',
  iconPath: '/path/to/iconPath',
  selectedIconPath: '/path/to/selectedIconPath'
})
qin.setTabBarItem({
  index: 0,
  text: 'text',
  iconPath: '/path/to/iconPath',
  selectedIconPath: '/path/to/selectedIconPath'
})

注意: 设置 iconfont 属性时,pages.json iconfontSrc 需要指定字体文件,参考下面的配置

json
// pages.json
{
  "tabBar": {
    "iconfontSrc": "static/iconfont.ttf",
    "list": [
      {
        "pagePath": "pages/index/index",
        "text": "Tab1",
        "iconfont": {
          "text": "\ue102",
          "selectedText": "\ue103",
          "fontSize": "17px",
          "color": "#000000",
          "selectedColor": "#0000ff"
        }
      }
    ]
  }
}
// pages.json
{
  "tabBar": {
    "iconfontSrc": "static/iconfont.ttf",
    "list": [
      {
        "pagePath": "pages/index/index",
        "text": "Tab1",
        "iconfont": {
          "text": "\ue102",
          "selectedText": "\ue103",
          "fontSize": "17px",
          "color": "#000000",
          "selectedColor": "#0000ff"
        }
      }
    ]
  }
}

qin.setTabBarStyle(OBJECT) ​

动态设置 tabBar 的整体样式

平台差异说明

H5微信小程序小红书小程序抖音小程序快手小程序
√√√√√

OBJECT 参数说明

属性类型默认值必填说明
colorString否tab 上的文字默认颜色, HexColor
selectedColorString否tab 上的文字选中时的颜色, HexColor
backgroundColorString否tab 的背景色, HexColor
borderStyleString否tabBar上边框的颜色, 仅支持 black/white
successFuntion否接口调用成功的回调函数
failFuntion否接口调用失败的回调函数
completeFuntion否接口调用结束的回调函数(调用成功、失败都会执行)

backgroundImage创建线性渐变说明

backgroundImage: linear-gradient(to top, #a80077, #66ff00);

目前暂不支持 radial-gradient(径向渐变)。

目前只支持两种颜色的渐变,渐变方向如下:

  • to right:从左向右渐变
  • to left:从右向左渐变
  • to bottom:从上到下渐变
  • to top:从下到上渐变
  • to bottom right:从左上角到右下角
  • to top left:从右下角到左上角

示例代码

js
qin.setTabBarStyle({
  color: '#FF0000',
  selectedColor: '#00FF00',
  backgroundColor: '#0000FF',
  borderStyle: 'white',
});
qin.setTabBarStyle({
  color: '#FF0000',
  selectedColor: '#00FF00',
  backgroundColor: '#0000FF',
  borderStyle: 'white',
});

qin.hideTabBar(OBJECT) ​

隐藏 tabBar

平台差异说明

H5微信小程序小红书小程序抖音小程序快手小程序
√√√√√

OBJECT 参数说明

属性类型默认值必填说明
animationbooleanfalse否是否需要动画效果,仅微信小程序、百度小程序、抖音小程序、快手小程序支持
successFuntion否接口调用成功的回调函数
failFuntion否接口调用失败的回调函数
completeFuntion否接口调用结束的回调函数(调用成功、失败都会执行)

qin.showTabBar(OBJECT) ​

显示 tabBar

平台差异说明

H5微信小程序小红书小程序抖音小程序快手小程序
√√√√√

OBJECT 参数说明

属性类型默认值必填说明
animationbooleanfalse否是否需要动画效果,仅微信小程序、百度小程序、抖音小程序、快手小程序支持
successFuntion否接口调用成功的回调函数
failFuntion否接口调用失败的回调函数
completeFuntion否接口调用结束的回调函数(调用成功、失败都会执行)

qin.setTabBarBadge(OBJECT) ​

为 tabBar 某一项的右上角添加文本。

平台差异说明

H5微信小程序小红书小程序抖音小程序快手小程序
√√√√√

OBJECT 参数说明

参数类型必填说明
indexNumber是tabBar 的哪一项,从左边算起
textString是显示的文本,不超过 3 个半角字符
successFunction否接口调用成功的回调函数
failFunction否接口调用失败的回调函数
completeFunction否接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

js
qin.setTabBarBadge({
  index: 0,
  text: '1',
});
qin.setTabBarBadge({
  index: 0,
  text: '1',
});

qin.removeTabBarBadge(OBJECT) ​

移除 tabBar 某一项右上角的文本。

平台差异说明

H5微信小程序小红书小程序抖音小程序快手小程序
√√√√√

OBJECT 参数说明

参数类型必填说明
indexNumber是tabBar 的哪一项,从左边算起
successFunction否接口调用成功的回调函数
failFunction否接口调用失败的回调函数
completeFunction否接口调用结束的回调函数(调用成功、失败都会执行)

qin.showTabBarRedDot(OBJECT) ​

显示 tabBar 某一项的右上角的红点。

平台差异说明

H5微信小程序小红书小程序抖音小程序快手小程序
√√√√√

OBJECT 参数说明

参数类型必填说明
indexNumber是tabBar 的哪一项,从左边算起
successFunction否接口调用成功的回调函数
failFunction否接口调用失败的回调函数
completeFunction否接口调用结束的回调函数(调用成功、失败都会执行)

qin.hideTabBarRedDot(OBJECT) ​

隐藏 tabBar 某一项的右上角的红点。

平台差异说明

H5微信小程序小红书小程序抖音小程序快手小程序
√√√√√

OBJECT 参数说明

参数类型必填说明
indexNumber是tabBar 的哪一项,从左边算起
successFunction否接口调用成功的回调函数
failFunction否接口调用失败的回调函数
completeFunction否接口调用结束的回调函数(调用成功、失败都会执行)

qin.onTabBarMidButtonTap(CALLBACK) ​

监听中间按钮的点击事件

平台差异说明

H5微信小程序小红书小程序抖音小程序快手小程序
√xxxx

注意

  • tabbar 是原生的,层级高于前端元素
  • 插件市场有封装的前端 tabbar ,但性能不如原生 tabbar
  • 以上大部分操作 tabbar 的 API 需要在 tabbar 渲染后才能使用,避免在 tabbar 未初始化前使用