微信小程序tabBar用法實(shí)例詳解
本文實(shí)例講述了微信小程序tabBar用法。分享給大家供大家參考,具體如下:
1、效果展示

2、原理:在app.json中配置tabBar屬性
{
"pages": [
"index",
"picDisplay"
],
"window": {
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "首頁",
"backgroundColor": "#eeeeee",
"backgroundTextStyle": "light",
"enablePullDownRefresh": false
},
"tabBar": {
"color":"#666666",
"selectedColor":"#06bd04",
"list": [{
"pagePath": "index",
"text": "首頁",
"iconPath": "images/index.png",
"selectedIconPath": "images/indexHL.png"
},{
"pagePath": "picDisplay",
"text": "圖片展示",
"iconPath": "images/picDisplay.png",
"selectedIconPath": "images/picDisplayHL.png"
}]
}
}
3、關(guān)鍵代碼
"tabBar": {
"color":"#666666",
"selectedColor":"#06bd04",
"list": [{
"pagePath": "index",
"text": "首頁",
"iconPath": "images/index.png",
"selectedIconPath": "images/indexHL.png"
},{
"pagePath": "picDisplay",
"text": "圖片展示",
"iconPath": "images/picDisplay.png",
"selectedIconPath": "images/picDisplayHL.png"
}]
}
4、操作方法
新建一個(gè)項(xiàng)目,打開app.json文件,將關(guān)鍵代碼復(fù)制到"window":{},后面,注意window的大括號前加逗號,如下圖

配置tabBar屬性值
"tabBar": {
//設(shè)置tabBar文字默認(rèn)顏色
"color":"#666666",
//設(shè)置tabBar文字被選中是的顏色
"selectedColor":"#06bd04",
//tab列表,數(shù)組類型,改數(shù)組內(nèi)至少要有兩個(gè)但不大于5個(gè)的tab對象
"list": [{
//設(shè)置tab跳轉(zhuǎn)頁面鏈接
"pagePath": "index",
//設(shè)置tab上的文字
"text": "首頁",
//設(shè)置tab上的默認(rèn)圖標(biāo)
"iconPath": "images/index.png",
//設(shè)置tab被選中時(shí)的圖標(biāo)
"selectedIconPath": "images/indexHL.png"
},{
"pagePath": "picDisplay",
"text": "圖片展示",
"iconPath": "images/picDisplay.png",
"selectedIconPath": "images/picDisplayHL.png"
}]
}
tabBar的5種常用屬性與配置說明:
1) color:未選擇字體顏色
2) selectedColor:選擇字體顏色
3) borderStyle:tabbar上方線的顏色white(僅支持白色和黑色)
4) backgroundColor:tabbar背景顏色
5) list:設(shè)置rab列表項(xiàng)(最少2個(gè),最多5個(gè)tab)。
另外,list作為數(shù)組屬性,其每一項(xiàng)又是一個(gè)對象,list可以設(shè)置4種屬性:
① text:設(shè)置tab上的文字
② iconPath:設(shè)置tab處于未激活狀態(tài)時(shí)顯示的圖片路徑。
③ selectedIconPath:設(shè)置tab處于激活狀態(tài)時(shí)的圖片路徑(iconPath與selectedIconPath圖片大小限制都是40KB)
④ pagePath:設(shè)置觸按tab時(shí)的跳轉(zhuǎn)頁面路徑(該頁面必須在pages中進(jìn)行了配置)
5、完整實(shí)例代碼點(diǎn)擊此處本站下載。
此外,微信小程序開發(fā)軟件下載地址如下:
https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html?t=201714
希望本文所述對大家微信小程序開發(fā)有所幫助。
- 微信小程序 (三)tabBar底部導(dǎo)航詳細(xì)介紹
- 微信小程序開發(fā)之實(shí)現(xiàn)選項(xiàng)卡(窗口頂部TabBar)頁面切換
- 微信小程序開發(fā)之Tabbar實(shí)例詳解
- 微信小程序 新建登錄頁并實(shí)現(xiàn)tabBar隱藏
- 微信小程序官方動態(tài)自定義底部tabBar的例子
- 微信小程序自定義tabBar在uni-app的適配詳解
- 微信小程序開發(fā)之tabbar圖標(biāo)和顏色的實(shí)現(xiàn)
- 微信小程序開發(fā)之選項(xiàng)卡(窗口底部TabBar)頁面切換
- 微信小程序自定義tabBar組件開發(fā)詳解
- 小程序自定義tabBar組件封裝
相關(guān)文章
JavaScript?WebSocket實(shí)現(xiàn)實(shí)時(shí)雙向聊天
這篇文章主要為大家詳細(xì)介紹了如何基于JavaScript?WebSocket實(shí)現(xiàn)實(shí)時(shí)雙向聊天,文中的示例代碼講解詳細(xì),有需要的小伙伴可以參考一下2024-04-04
JavaScript實(shí)現(xiàn)生成GUID(全局統(tǒng)一標(biāo)識符)
這篇文章主要介紹了JavaScript實(shí)現(xiàn)生成GUID(全局統(tǒng)一標(biāo)識符),本文寫成了一個(gè)GUID生成類,使用也非常方便,需要的朋友可以參考下2014-09-09
JS實(shí)現(xiàn)點(diǎn)擊鏈接切換顯示隱藏內(nèi)容的方法
這篇文章主要介紹了JS實(shí)現(xiàn)點(diǎn)擊鏈接切換顯示隱藏內(nèi)容的方法,涉及javascript鼠標(biāo)事件響應(yīng)及頁面元素屬性動態(tài)變換相關(guān)操作技巧,需要的朋友可以參考下2017-10-10

