在做微信小程序換皮膚的時候,需要動態修改菜單欄(TabBar)和導航欄(NavigationBar)
但是在小程序中它們的樣式是寫在app.json里面,而且app.json是靜態編譯,運行時哪怕你修改了里面的值,也是不起做作用的.
不過官方提供了動態修改兩個樣式的api.
動態修改NavigationBar
wx.setNavigationBarColor({ frontColor:"#ffffff", backgroundColor:'#000000' });
動態修改TabBar
wx.setTabBarStyle({ color: '#FF0000', selectedColor: '#00FF00', backgroundColor: '#0000FF', borderStyle: 'white' }); wx.setTabBarItem({ index: 0, text: 'text', iconPath: '/path/to/iconPath', selectedIconPath: '/path/to/selectedIconPath' });
官方提供的其他接口