wxtabBar的设置(右上角红点和消息,以及显示与隐藏)

wxml

<view class="title">tabBar设置</view>
<view class="demo-box">
<view class="title">1右上角文本设置</view>
<button type="primary" size="mini" bindtap="setText">添加文本</button>
<button type="primary" size="mini" bindtap="removeText">取消文本</button>
</view>
<view class="demo-box">
<view class="title">2右上角红点设置</view>
<button type="primary" size="mini" bindtap="showRedDot">添加红点</button>
<button type="primary" size="mini" bindtap="hideRedDot">取消红点</button>
</view>
<view class="demo-box">
<view class="title">3tabBar样式设置</view>
<button type="primary" size="mini" bindtap="setBarStyle">整体设置</button>
<button type="primary" size="mini" bindtap="setColor">单项设置</button>
</view>
<view class="demo-box">
<view class="title">4tabBar的显示与隐藏</view>
<button type="primary" size="mini" bindtap="showTabBar">显示</button>
<button type="primary" size="mini" bindtap="hideTabBar">隐藏</button>
</view>

js

Page({
  data: {
  
  },
  //设置文本
  setText:function(){
    wx.setTabBarBadge({
      index: 1,
      text: '99',
    })
  },
  //取消文本
  removeText:function(){
    wx.removeTabBarBadge({
      index: 1,
    })
  },
  //显示红点
  showRedDot:function(){
    wx.showTabBarRedDot({
      index: 1,
    })
  },
  //隐藏红点
  hideRedDot:function(){
    wx.hideTabBarRedDot({
      index: 1,
    })
  },
  //设置tabBar整体样式
  setBarStyle:function(){
    wx.setTabBarStyle({
      Color: '#ff0000',
      selectedColor:'#0000ff'
    })
  },
  //设置tabBar单项样式
  setBarItemStyle:function(){
    wx.setTabBarItem({
      index: 1,
      text:'首页',
      iconPath:'../image/1.png',
      selectedIconPath:'../image/3.png'
    })
  },
  //还原tabBar样式
  resetBarStyle:function(){
    wx.setTabBarItem({
      index: 1,
      text:'tabBar例题',
      iconPath:'../image/4.png',
      selectedIconPath:'../image/5.png'
    })
    wx.setTabBarStyle({
      Color: '#000000',
      selectedColor:'#1aad19'
    })
  },
  //显示TabBar
  showTabBar:function(){
    wx.showTabBar({})
  },
  //隐藏TabBar
  hideTabBar:function(){
    wx.hideTabBar({})
  },
)}

app.json

{
  "tabBar": {
    "color": "#000",
    "selectedColor": "1aad19",
    "list": [
      {
        "pagePath": "pages/index/index",
        "iconPath": "./pages/image/1.png",
        "selectedIconPath": "./pages/image/3.png",
        "text": "首页"
      },
      {
        "pagePath": "pages/tabBar/tabBar",
        "iconPath": "./pages/image/4.png",
        "selectedIconPath": "./pages/image/5.png",
        "text": "tabBar例题"
      }
    ]
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值