angular – Ionic-3如何动态改变离子主题
发布时间:2020-12-17 18:10:36 所属栏目:安全 来源:网络整理
导读:我需要动态更改我的离子应用主题. $color主题值应该从数据库中呈现 给我一些想法来简化这个! 解决方法 26-02-2019 使用Ionic 4和CSS 4,这是一项非常简单的任务.请参阅 this article . service.ts import { Injectable,Inject } from '@angular/core';import
我需要动态更改我的离子应用主题. $color主题值应该从数据库中呈现
给我一些想法来简化这个! 解决方法
26-02-2019
使用Ionic 4和CSS 4,这是一项非常简单的任务.请参阅this article. service.ts import { Injectable,Inject } from '@angular/core'; import { DOCUMENT } from '@angular/common'; import { DomController } from '@ionic/angular'; interface Theme { name: string; styles: ThemeStyle[]; } interface ThemeStyle { themeVariable: string; value: string; } @Injectable({ providedIn: 'root' }) export class ThemeSwitcherService { private themes: Theme[] = []; private currentTheme: number = 0; constructor(private domCtrl: DomController,@Inject(DOCUMENT) private document) { this.themes = [ { name: 'day',styles: [ { themeVariable: '--ion-color-primary',value: '#f8383a'},{ themeVariable: '--ion-color-primary-rgb',value: '248,56,58'},{ themeVariable: '--ion-color-primary-contrast',value: '#ffffff'},{ themeVariable: '--ion-color-primary-contrast-rgb',value: '255,255,255'},{ themeVariable: '--ion-color-primary-shade',value: '#da3133'},{ themeVariable: '--ion-color-primary-tint',value: '#f94c4e'},{ themeVariable: '--ion-item-ios-background-color',{ themeVariable: '--ion-item-md-background-color',{ themeVariable: '--ion-tabbar-background-color',value: '#fff'},{ themeVariable: '--ion-tabbar-ios-text-color-active',value: '#000000'},{ themeVariable: '--ion-tabbar-md-text-color-active',{ themeVariable: '--ion-background-color',value: '#f94c4e'} ] },{ name: 'night',value: '#222428'},value: '34,34,34'},value: '#1e2023'},value: '#383a3e'},value: '#717171'},value: '#383838'} ] } ] } cycleTheme(): void { if(this.themes.length > this.currentTheme + 1){ this.currentTheme++; } else { this.currentTheme = 0; } this.setTheme(this.themes[this.currentTheme].name); } setTheme(name): void { let theme = this.themes.find(theme => theme.name === name); this.domCtrl.write(() => { theme.styles.forEach(style => { document.documentElement.style.setProperty(style.themeVariable,style.value); }); }); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- j2m2访问dotnet Webservice--以前写过,被到处转载,绝对原版
- AngularJS UI路由器 – 使用templateUrl时$state.current.n
- Angular和Spring Boot:配置使它们有效地协同工作
- WebService的简单示例
- Bootstrap响应式前端框架笔记十二——巨幕与缩略图
- vim – 如何在插入模式下返回上一个缩进级别?
- 调用天气预报WebService
- angularjs – 如何删除绑定到$document的单击
- 【webservice】818开发webservice过程中遇到的异常
- AngularJS 2 – 使用哪种语言? (Typescript,Javascript,Da