【问题标题】:Ionic how to know programmatically if the dark theme is applied?离子如何以编程方式知道是否应用了深色主题?
【发布时间】:2021-06-16 09:29:50
【问题描述】:

我正在使用 Ionic angular 和 Mapbox。我也想知道加载 mapbox 主题时应用了哪个主题...

类似这样的:

const currentIonicTheme = ionic.theme.apllied; // here is where I want to know how to get the current theme in the app
const map = new mapboxgl.Map({
  style: `mapbox://styles/mapbox/${currentIonicTheme}-v10`,
  center: [this.lng, this.lat],
  zoom: 15.5,
  pitch: 45,
  bearing: -17.6,
  container: 'map',
  antialias: true
});

有什么方法可以根据应用中的主题调用 /mapbox/light-v10 或 /mabox/dark-v10 吗?

【问题讨论】:

标签: angular ionic-framework android-dark-theme darkmode


【解决方案1】:

使用这个插件: cordova-plugin-theme-detection

import { ThemeDetection } from "@ionic-native/theme-detection/ngx";

@Component({
  selector: "app-home",
  templateUrl: "home.page.html"
})
export class HomePage {
  constructor(private themeDetection: ThemeDetection) {}

  private async isAvailable(): Promise<ThemeDetectionResponse> {
    try {
      let dark_mode_available: ThemeDetectionResponse = await this.themeDetection.isAvailable();
    } catch (e) {
      console.log(e);
    }
  }

  private async isDarkModeEnabled(): Promise<ThemeDetectionResponse> {
    try {
      let dark_mode_enabled: ThemeDetectionResponse = await this.themeDetection.isDarkModeEnabled();
    } catch (e) {
      console.log(e);
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-29
    • 2020-10-03
    • 2020-12-03
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    • 2013-02-28
    相关资源
    最近更新 更多