如何更改TimePicker对话框的样式

时间:2015-08-13 09:45:44

标签: android

是否可以更改TimePicker配色方案?

我已尝试过,但TimePicker弹出窗口会全屏打开。

 TimePickerDialog mTimePicker;

    mTimePicker = new TimePickerDialog(AddAlarm.this,R.style.Time_picker, new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker timePicker, int selectedHourLocal, int selectedMinuteLocal) {

        }
    }, hour, minute, false);//Yes 24 hour time
    mTimePicker.setTitle("Select Time");
    mTimePicker.show();

风格是

 <style name="Time_picker">
    <item name="android:numbersTextColor" tools:targetApi="lollipop">#ffffff</item>
    <item name="android:numbersBackgroundColor" tools:targetApi="lollipop">#643B85</item>
    <item name="android:numbersSelectorColor" tools:targetApi="lollipop">#88000000</item>
    <item name="android:headerBackground">#643B85</item>
</style>

1 个答案:

答案 0 :(得分:0)

使用五种内置AlertDialog主题之一:

THEME_TRADITIONAL - 传统(前Holo)提醒对话框主题

THEME_HOLO_DARK - 深色背景的全息警示主题

THEME_HOLO_LIGHT - 具有浅色背景的全息警示主题

THEME_DEVICE_DEFAULT_DARK - 设备的默认提醒主题,背景为深色。

THEME_DEVICE_DEFAULT_LIGHT - 设备的默认提醒主题,背景为浅色。

例如:

       MyTimePickerDialog timePickerDialog = new MyTimePickerDialog (AddAlarm.this,
        TimePickerDialog.THEME_HOLO_DARK, timeSetListener, 0, 0, true);