欢迎光临
我们一直在努力

九八云百度小程序教程:swan.setTabBarStyle

  • swan.setTabBarStyle
    • 方法参数
      • object 参数说明
    • 示例
      • 图片示例
      • 代码示例 1:动态设置
      • 代码示例 2:设置 borderStyle
      • 代码示例 3:tab 的默认样式可在 app.json 中设置
    • 错误码
      • Android
      • iOS

    swan.setTabBarStyle

    解释:动态设置 tabBar 的整体样式,底部标签栏位于小程序底部,方便用户在不同功能模块之间进行快速切换。为保证可用性,底部导航栏承载 2-5 个功能,如果超出 5 个功能项,请酌情移入页面或菜单内。设计文档详见 底部标签栏。

    方法参数

    Object object

    object 参数说明

    属性名 类型 必填 默认值 说明

    color

    HexColor

    tab 上的文字默认颜色

    selectedColor

    HexColor

    tab 上的文字选中时的颜色

    backgroundColor

    HexColor

    tab 的背景色

    borderStyle

    String

    tabbar 上边框的颜色, 有效值 black/white

    success

    Function

    接口调用成功的回调函数

    fail

    Function

    接口调用失败的回调函数

    complete

    Function

    接口调用结束的回调函数(调用成功、失败都会执行)

    示例

    扫码体验

    代码示例

    请使用百度APP扫码

    图片示例

    代码示例 1:动态设置

    在开发者工具中打开

    在开发者工具中打开

    在 WEB IDE 中打开

    • SWAN
    • JS
    
     
    1. <view class="wrap">
    2. <button type="primary" bindtap="customStyle">
    3. {{ !hasCustomedStyle ? '自定义Tab样式' : '移除自定义样式'}}
    4. </button>
    5. </view>

    设计指南

    标签项应明确区分默认态和选中态,方便用户定位当前所在位置;图标风格应保存一致;每个标签项的文字信息不应超出 5 个中文字符,否则将被截断。
    配置背景颜色时,请注意整体页面效果、及标签项的可读性和可用性。

    错误

    图标的默认态和选中态无明显区别,只能通过文字颜色判断当前位置。

    错误

    图标与文字信息颜色不统一,背景与标签配色不协调,过多使用高饱和度颜色等,均会降低阅读的舒适度。

    代码示例 2:设置 borderStyle

    在开发者工具中打开

    在开发者工具中打开

    在 WEB IDE 中打开

    • JS
    
     
    1. Page({
    2. setTabBarStyle() {
    3. swan.setTabBarStyle({
    4. // black
    5. color: '#000',
    6. // red
    7. selectedColor: '#FF0000',
    8. backgroundColor: '#FFFFBD',
    9. // 可选值还有white
    10. borderStyle: 'black',
    11. success: () => {
    12. console.log('setTabBarStyle success');
    13. },
    14. fail: err => {
    15. console.log('setTabBarStyle fail', err);
    16. }
    17. });
    18. }
    19. });

    代码示例 3:tab 的默认样式可在 app.json 中设置

    在开发者工具中打开

    在开发者工具中打开

    在 WEB IDE 中打开

    • JSON
    
     
    1. "tabBar": {
    2. "list": [
    3. {
    4. "pagePath": "pages/index/index",
    5. "text": "首页",
    6. "iconPath": "/images/API_normal.png",
    7. "selectedIconPath": "/images/API_selected.png"
    8. },
    9. {
    10. "pagePath": "pages/detail/detail",
    11. "text": "详情",
    12. "iconPath": "/images/component_normal.png",
    13. "selectedIconPath": "/images/component_selected.png"
    14. }
    15. ],
    16. "backgroundColor" : "#ffffff",
    17. "borderStyle": "white",
    18. "color": "#000",
    19. "selectedColor": "#6495ED"
    20. }

    错误码

    Android

    错误码 说明

    1001

    执行失败

    iOS

    错误码 说明

    1001

    当前页面不含 tabbar

    赞(0) 打赏
    未经允许不得转载:九八云安全 » 九八云百度小程序教程:swan.setTabBarStyle

    评论 抢沙发