当前位置:网站首页>微信小程序中使用tabBar
微信小程序中使用tabBar
2022-07-02 01:17:00 【richest_qi】
前景知识
前面我们学习过:在app.json里对小程序进行全局配置,app.json的文件内容是一个JSON对象,包含很多属性,其中一个常用属性就是 tabBar。如果小程序是一个多tab应用,就可以通过tabBar指定tab栏的表现,以及tab切换时显示的对应页面。
tabBar 的属性值也是一个对象,该对象包含以下常用属性:
color,tab上文字的默认颜色,仅支持十六进制颜色,必填。selectedColor,tab上文字选中时的颜色,仅支持十六进制颜色,必填。backgroundColor,tab的背景颜色,仅支持十六进制颜色,必填。position,tabBar的位置,仅支持两个值:bottom和top,默认值是bottom。list,tab的列表,是一个数组,数组元素最少2个,最多5个。每个数组元素都是一个对象,包含以下属性值:pathPath,页面路径,必须在pages中定义,必填。text,tab上的文字,必填。iconPath,图片路径,非必填。icon大小限制为40kb,建议尺寸为81px*81px,不支持网络图片。当position值为top时,不显示icon。selectedIconPath,选中时的图片路径,非必填。icon大小限制为40kb,建议尺寸为81px*81px,不支持网络图片。当position为top时,不显示icon。
小程序项目
pages下新建Page:home(主页)、camera(拍照)、user(个人中心)。
- pages/home/
home.wxml、home.wxss、home.js、home.json - pages/camera/
camera.wxml、camera.wxss、camera.js、camera.json - pages/user/
user.wxml、user.wxss、user.js、user.json
项目根目录下新建文件夹:static,static下新建文件夹:images,images下新建文件夹:tabIcons,tabIcons下存放tabBar要用到的图标。
代码涉及的主要文件有:
- app.json
- pages/home/home.wxml
- pages/camera/camera.wxml
- pages/user/user.wxml

app.json
{
"pages": [
"pages/home/home",
"pages/camera/camera",
"pages/user/user"
],
"window": {
"navigationBarBackgroundColor": "#971a22",
"navigationBarTitleText": "首页",
"navigationBarTextStyle": "white"
},
"tabBar": {
"color": "#000000",
"selectedColor": "#971a22",
"backgroundColor": "#ffffff",
"list": [
{
"pagePath": "pages/home/home",
"text": "主页",
"iconPath": "/static/images/tabIcons/home.png",
"selectedIconPath": "/static/images/tabIcons/home-fill.png"
},
{
"pagePath": "pages/camera/camera",
"text": "拍照",
"iconPath": "/static/images/tabIcons/camera.png",
"selectedIconPath": "/static/images/tabIcons/camera-fill.png"
},
{
"pagePath": "pages/user/user",
"text": "个人中心",
"iconPath": "/static/images/tabIcons/user.png",
"selectedIconPath": "/static/images/tabIcons/user-fill.png"
}
]
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
pages/home/home.wxml
<view class="camera">
Here is Home Page
</view>
pages/camera/camera.wxml
<view class="camera">
Here is Camera Page
</view>
pages/user/user.wxml
<view class="camera">
Here is User Page
</view>

相关链接
边栏推荐
- Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
- 2022年6月国产数据库大事记
- Global and Chinese markets of edge AI software 2022-2028: Research Report on technology, participants, trends, market size and share
- cookie、session、tooken
- [IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card
- [eight sorts ②] select sort (select sort, heap sort)
- Zak's latest "neural information transmission", with slides and videos
- What skills does an excellent software tester need to master?
- Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
- 【八大排序②】选择排序(选择排序,堆排序)
猜你喜欢

GL Studio 5 安装与体验

I'll teach you to visit Amazon RDS for a year and build a MySQL cloud database (only 10 minutes, really fragrant)

The 8-year salary change of testers makes netizens envy it: you pay me one year's salary per month

【八大排序②】选择排序(选择排序,堆排序)

【图像增强】基于Frangi滤波器实现血管图像增强附matlab代码

The concept and application of Cartland number

6-3 vulnerability exploitation SSH environment construction
![[IVX junior engineer training course 10 papers] 06 database and services](/img/68/967566fc2f1d0b93ecd78bdb208b64.jpg)
[IVX junior engineer training course 10 papers] 06 database and services

How can I batch produce the same title for the video?

Iclr2022 | spherenet and g-spherenet: autoregressive flow model for 3D molecular graph representation and molecular geometry generation
随机推荐
Day 13 of hcip (relevant contents of BGP agreement)
Single chip microcomputer -- hlk-w801 transplant NES simulator (III)
Infiltration records of CFS shooting range in the fourth phase of the western regions' Dadu Mansion
Exclusive delivery of secret script move disassembly (the first time)
Part 29 supplement (XXIX) basis of ECMAScript
Basic number theory -- Gauss elimination
BiLSTM-CRF代码实现
GL Studio 5 安装与体验
【八大排序④】归并排序、不基于比较的排序(计数排序、基数排序、桶排序)
【八大排序③】快速排序(动图演绎Hoare法、挖坑法、前后指针法)
什么是商业养老保险?商业养老保险安全靠谱吗?
The author is more willing to regard industrial Internet as a concept much richer than consumer Internet
How does schedulerx help users solve the problem of distributed task scheduling?
[conference resources] the Third International Conference on Automation Science and Engineering in 2022 (jcase 2022)
Shell Function
【八大排序②】选择排序(选择排序,堆排序)
Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
ACM tutorial - quick sort (regular + tail recursion + random benchmark)
[eight sorting ③] quick sorting (dynamic graph deduction Hoare method, digging method, front and back pointer method)
学习笔记25--多传感器前融合技术