当前位置:网站首页>Mini Program_Dynamic setting of tabBar theme skin
Mini Program_Dynamic setting of tabBar theme skin
2022-08-05 04:13:00 【Yixi Muze】
序:Need to dynamically set some background of the page、按钮状态、文字的颜色,图片、图标等等,包括tabBaricon and text color,Toggle button unified settings,This is easier to implement on the page,按理说tabBarThe settings are also simple,确实是!as long as you can calltabBarThe method of the component can switch the theme skin,The key is whether you will use the applet method.
1、tabBar自定义
配置自定义tabBar的方法可以参考官方文档,This doesn't bother me anymore,Get familiar with this first,Speaking of other;
2、Dynamically set the background、按钮状态、文字的颜色,图片、图标等等
前提工作:主题样式文件 common/theme.wxssand theme images folder/static/image/v1,/static/image/v2,如下图:
Replace styles in each desired theme xxx.wxss The header introduces the theme file
@import "./../common/theme.wxss";
1)首先在 app.js Set a theme parameter in the global file
globalData: {
theme: 1, // 主题
}
2)Then set parameters on other pages
data: {
theme: 1,
},
onShow(){
let that = this;
that.setData({
theme: app.globalData.theme,
})
},
.wxml
<view class="limit_width theme_v{
{theme}}"> ... </view>
3)Last action on the settings page
setup.wxml
<view class="limit_width theme_v{
{theme}}">
<view class="item">
<view class="theme_tle">设置主题:</view>
<view class="flex">
<view bindtap="themeTab" class="theme_tab {
{theme==1?'tab_bg_br':''}}" data-num="1">新绿(默认)</view>
<view bindtap="themeTab" class="theme_tab {
{theme==2?'tab_bg_br':''}}" data-num="2">海蓝</view>
</view>
</view>
</view>
setup.js
data: {
theme: 1,
},
onLoad(options) {
this.setData({
theme: app.globalData.theme,
})
},
// 主题切换(逸曦穆泽)
themeTab(e){
let num = parseInt(e.currentTarget.dataset.num);
this.setData({theme: num});
app.globalData.theme = num; // 全局更新
this.getTabBar().watchBack(); // (逸曦穆泽)调用自定义 tabbar 的方法
// 保存到本地
wx.setStorage({
key: "themeSkin",
data: num,
})
},
3、动态设置tabBar
// (逸曦穆泽)custom-tab-bar/index.js
const app = getApp();
let themeColor = ["#515151","#515151","#000"];
let themeActiveColor = ["#94AC56","#94AC56","#185F95"];
Component({
data: {
theme: 1,
selected: 1,
color: "#515151",
selectedColor: "#94AC56",
list: [{
"pagePath": "/pages/home/home",
"iconPath": "/static/image/nav_home.png",
"selectedIconPath": "/static/image/v1/nav_home.png",
"text": "首页"
},{
"pagePath": "/pages/setup/setup",
"iconPath": "/static/image/nav_setup.png",
"selectedIconPath": "/static/image/v1/nav_setup.png",
"text": "设置"
}],
},
methods: {
// (逸曦穆泽)监听并回调
watchBack() {
var that = this;
let num = app.globalData.theme;
let listUpd = [{
"pagePath": "/pages/home/home",
"iconPath": "/static/image/nav_home.png",
"selectedIconPath": "/static/image/v"+num+"/nav_home.png",
"text": "首页"
},{
"pagePath": "/pages/setup/setup",
"iconPath": "/static/image/nav_setup.png",
"selectedIconPath": "/static/image/v"+num+"/nav_setup.png",
"text": "设置"
}];
that.setData({
theme: num,
color: themeColor[num],
selectedColor: themeActiveColor[num],
list: listUpd,
})
},
switchTab(e){
var that = this;
const data = e.currentTarget.dataset;
const url = data.url;
wx.switchTab({ url });
that.setData({
selected: data.index
});
}
},
})
.wxml
<view class="tabbar theme_v{
{theme}}"> ... </view>
to put it simply,其实也很简单,Just use the class-level styles from the theme style file,js 控制了 theme 参数;
难点在于 tabbar 的切换,怎么调用?肯定是调用 custom-tab-bar/index.js 下的方法,Get the global theme parameter settings into it;还有一个Topic echo的问题,可以自己去实现,这个也很简单,当然,Leave a message below if you really need it.
效果图就不贴了,This is something that involves companies and customers!
参考文章:
WeChat applet dynamics设置tab-bar_Eating hot pot tonight yay blog-CSDN博客_WeChat applet dynamicstabbar
边栏推荐
- DEJA_VU3D - Cesium功能集 之 056-智图Arcgis地图纠偏
- 大佬们,我注意到mysql cdc connector有参数scan.incremental.sna
- UE4 在游戏运行时更改变量 (通过鼠标滑轮来更改第一人称角色的最大行走速度)
- The most comprehensive exam questions for software testing engineers in 2022
- 【8.2】代码源 - 【货币系统】【硬币】【新年的问题(数据加强版)】【三段式】
- Bosses, I noticed that a mysql CDC connector parameters scan. The incremental. Sna
- JeeSite新建报表
- Why did you start preparing for the soft exam just after the PMP exam?
- 35岁的软件测试工程师,月薪不足2W,辞职又怕找不到工作,该何去何从?
- [MRCTF2020] Ezpop (detailed)
猜你喜欢
bytebuffer use demo
Haproxy搭建Web群集
不看后悔,appium自动化环境完美搭建
[Geek Challenge 2019]FinalSQL
C+ +核心编程
[TA-Frost Wolf_may-"Hundred Talents Project"] Graphics 4.3 Real-time Shadow Introduction
How to solve the three major problems of bank data collection, data supplementary recording and index management?
[SWPU2019]Web1
UE4 在游戏运行时更改变量 (通过鼠标滑轮来更改第一人称角色的最大行走速度)
程序开发的一些常规套路(一)
随机推荐
What is the function of industrial-grade remote wireless transmission device?
MySql的索引学习和使用;(本人觉得足够详细)
DNS被劫持如何处理?
NPDP证书含金量高吗?跟PMP相比?
数据库设计的酸(ACID)碱(BASE)原则
测试薪资这么高?刚毕业就20K
[8.2] Code Source - [Currency System] [Coins] [New Year's Questions (Data Enhanced Edition)] [Three Stages]
多御安全浏览器 V10.8.3.1 版正式发布,优化多项内容
The production method of the powered small sailboat is simple, the production method of the electric small sailboat
七夕节代码表白
UE4 后期处理体积 (角色受到伤害场景颜色变淡案例)
浅析主流跨端技术方案
七夕节赚徽章拉
1007 Climb Stairs (贪心 | C思维)
[8.3] Code Source - [meow ~ meow ~ meow~] [tree] [and]
Event parse tree Drain3 usage and explanation
36-Jenkins-Job Migration
为什么刚考完PMP,就开始准备软考了?
What is the difference between SAP ERP and ORACLE ERP?
【8.2】代码源 - 【货币系统】【硬币】【新年的问题(数据加强版)】【三段式】