In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to achieve the night mode function in Ionic3, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
1. Create a theme style
Create theme.light.scss and theme.dark.scss files under. / src/theme folder, which are used for setting daytime mode and night mode respectively.
Theme.light.scss:
.light-theme {ion-content {background-color: # f4f4f4;} .item {background-color: # fff;} ion-textarea {background-color: # fff;}. Toolbar-background {background-color: # f8f8f8;} .tab-button {background-color: # f8f8f8;}
Theme.dark.scss:
.dark-theme {ion-content {background-color: # 555;} .item {background-color: # 555;} ion-textarea {background-color: # 666;} .toolbar-background {background-color: # 444;} .tab-button {background-color: # 444;}}
These are my two theme styles, which readers can write on demand.
two。 Import variables.scss@import "theme.light"; @ import "theme.dark"; 3. Create provider
Terminal operation:
Ionic g provider setting-data
Setting-data.ts:
Import {Injectable} from'@ angular/core';import {BehaviorSubject} from "rxjs/BehaviorSubject"; @ Injectable () export class SettingDataProvider {/ / true: dark-theme / / false: light-theme theme: BehaviorSubject; constructor () {this.theme = new BehaviorSubject (false);} setActiveTheme (theme) {this.theme.next (theme);} getActiveTheme () {return this.theme.asObservable ();}} 4. Create page
Terminal operation:
Ionic g page setting
Setting.html
Set personalization night mode
Setting.ts
Import {Component} from'@ angular/core';import {IonicPage, NavController, NavParams, ToastController} from 'ionic-angular';import {SettingDataProvider} from ".. / providers/setting-data/setting-data"; @ IonicPage () @ Component ({selector:' page-setting', templateUrl: 'setting.html',}) export class SettingPage {theme: boolean; constructor (public navCtrl: NavController, public navParams: NavParams, public toastCtrl: ToastController, public settingDataProvider: SettingDataProvider) {this.getActiveTheme () } getActiveTheme () {this.settingDataProvider.getActiveTheme () .subscribe (theme = > {this.theme = theme;});} toggleTheme () {if (! this.theme) {this.presentToast ('Night mode will fail after closing the application');} this.settingDataProvider.setActiveTheme (! this.theme);} presentToast (message: string) {let toast = this.toastCtrl.create ({message: message, duration: 2000}) Toast.present () .then (value = > {return value;});} 5. Apply a theme at the App entrance
App.html
App.component.ts
Import {Component} from'@ angular/core';import {Platform} from 'ionic-angular';import {StatusBar} from' @ ionic-native/status-bar';import {SplashScreen} from'@ ionic-native/splash-screen';import {SettingDataProvider} from ".. / providers/setting-data/setting-data"; @ Component ({templateUrl: 'app.html'}) export class MyApp {rootPage: any =' TabsPage'; theme: string Constructor (platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, settingDataProvider: SettingDataProvider) {settingDataProvider.getActiveTheme (). Subscribe (theme = > {if (theme) {this.theme = 'dark-theme';} else {this.theme =' light-theme';}}); platform.ready (). Then () = > {statusBar.styleDefault (); splashScreen.hide ();}) }} the above content is how to implement the night mode function in Ionic3. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.