TimePicker and TimePickerDialog can be presented in two different modes: spinner and clock.
[TimePicker/TimePickerDialog] clock mode (default):
Usually clock mode is the default setting, so clock mode can be set without any extra attributes.
[TimePicker] clock/spinner mode (xml attribute):
Changing view mode of TimePicker is simple. Adding the xml attribute below would switch between modes.
android:timePickerMode=“clock” / “spinner”
Unlike TimePicker, there is no direct interface to set xml attribute to the TimePickerDialog, this method does not work for TimePickerDialog.
[TimePicker/TimePickerDialog] clock/spinner mode (style):
Here is the method that works for both TimePicker and TimePickerDialog.
- create new TimePicker style
- override android:timePickerStyle
NOTE: Theme.MyApp should be used as the target Application/Activity theme
After create new TimePickerStyle and set it as android:timePickerStyle, all your TimePicker and TimePickerDialog will be presented in the mode you selected without extra attributes.
Extra: what happens if you set different timePickerMode under both MyTimePickerStyle and TimePicker component in layout.xml?
→ TimePicker will follow the xml attribute under TimePicker component in layout.xml. The xml attribute under View component declaration has higher priority than the one in the theme.xml.