简体   繁体   中英

How to correctly set androidTheme in cordova-plugin-datepicker plugin

I can't get any of the setting options for androidTheme to work for the DatePicker plugin for Ionic/Cordova listed in http://ionicframework.com/docs/v2/native/DatePicker/

The value options read:

Values: THEME_TRADITIONAL | THEME_HOLO_DARK | THEME_HOLO_LIGHT | THEME_DEVICE_DEFAULT_DARK | THEME_DEVICE_DEFAULT_LIGHT

But, for example,

options = {
  date: new Date(),
  mode: 'date',
  androidTheme: 'THEME_DEVICE_DEFAULT_LIGHT'
}

does nothing to change the theme option. No matter what I try, I still get this:

在此处输入图片说明

The docs are a little confusing since the values listed in the docs are strings, but androidTheme actually takes an int .

Choose the theme of the picker

Type: Int

Values: THEME_TRADITIONAL | THEME_HOLO_DARK | THEME_HOLO_LIGHT | THEME_DEVICE_DEFAULT_DARK | THEME_DEVICE_DEFAULT_LIGHT

Default: THEME_TRADITIONAL

Practically, the values map to:

THEME_TRADITIONAL = 1
THEME_HOLO_DARK = 2
THEME_HOLO_LIGHT = 3
THEME_DEVICE_DEFAULT_DARK = 4
THEME_DEVICE_DEFAULT_LIGHT = 5

So, depending on your androidTheme, your var option would read:

options = {
  date: new Date(),
  mode: 'date',
  androidTheme: 5, // because THEME_DEVICE_DEFAULT_LIGHT = 5
}

You can use :

options = {
  date: new Date(),
  mode: 'date',
  androidTheme: datePicker.ANDROID_THEMES.THEME_HOLO_LIGHT
}

Worked for me :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM