Custom tabBar

View Markdown

Last edited on 2026-06-16

基础库 2.5.0 开始支持,低版本需做兼容处理。

Custom tabBar allows developers to set tabBar styles more flexibly to meet various personalized scenarios.

In custom tabBar mode:

  • To ensure compatibility with lower versions and distinguish which pages are tab pages, tabBar configuration items must be fully declared, but these fields will not apply to the rendering of the custom tabBar.
  • Developers must provide a custom component to render the tabBar, where all tabBar styles are rendered by this custom component. It is recommended to use cover-view + cover-image components fixed at the bottom to render styles, ensuring the tabBar has a relatively high layer level.
  • Interfaces related to tabBar styles, such as wx.setTabBarItem, will become invalid.
  • The custom tabBar component instance under each tab page is different. You can obtain the custom tabBar component instance of the current page through the getTabBar interface under the custom component.

Note: To implement the tab selection state, you must obtain the component instance via the getTabBar interface in the current page and call setData to update the selection state. Please refer to the code example at the bottom.

Usage Flow

1. Configuration

  • Set the custom field in the tabBar item within app.json, and also complete the other tabBar-related configurations.
  • Declare the usingComponents item in the JSON of all tab pages, or enable it globally in app.json.

Example:

{
  "tabBar": {
    "custom": true,
    "color": "#000000",
    "selectedColor": "#000000",
    "backgroundColor": "#000000",
    "list": [{
      "pagePath": "page/component/index",
      "text": "Component"
    }, {
      "pagePath": "page/API/index",
      "text": "API"
    }]
  },
  "usingComponents": {}
}

2. Add tabBar code files

Add entry files under the root directory of the code:

custom-tab-bar/index.js
custom-tab-bar/index.json
custom-tab-bar/index.wxml
custom-tab-bar/index.wxss

3. Write tabBar Code

Simply implement it using a custom component; this custom component fully takes over the rendering of the tabBar. Additionally, a new getTabBar interface is available for custom components, which allows retrieving the custom tabBar component instance under the current page.

Sample Code

在开发者工具中预览效果

skyline Mode

When using the skyline rendering mode, the following adaptations are required:

1. tabBar Component Style Compatibility

  • The root component of tabBar requires pointer-events: auto
  • The positioning of the root component of tabBar must be position: absolute
<view class="tab-bar">
  <!-- tabbar item-->
</view>
.tab-bar {
  pointer-events: auto;
  position: absolute;
}

2. getTabBar Callback Function

In Skyline mode, the getTabBar interface on pages/components retrieves the tabBar instance via an asynchronous callback.

Page({
  getInstance() {
    if (typeof this.getTabBar === 'function' ) {
      this.getTabBar((tabBar) => {
        tabBar.setData({
          selected: 0
        })
      })
    }
  }
})

Skyline Sample Code

在开发者工具中预览效果