The TimePickerDialog widget in PreferenceScreen in landscape mode is too small. screenshot
I've tried out both approaches (PreferenceActivity and PreferenceFragments) according to these instructions: TimePicker in PreferenceScreen
The TimePickerDialog layout is empty in landscape mode, when using a timepicker title. So I've disabled the title. In the PreferenceActivity Version I've added setDialogTitle("");
to TimePreference. In the PreferenceFragmentCompat Version I've added the following code to TimePreference:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.setTitle("");
return dialog;
}
In both versions, the clock is presented in landscape, but the widget is too small; (I have no problems with too small widgets, when using timepickerdialogs without titles outside of the PreferenceScreen)
Any ideas how to implement TimePicker in the PreferenceScreen, so that the layout is ok in landscape mode?
Same problem here on a Motorola Moto G5 Plus phone, Android 7, in landscape mode. Portrait is ok. From the log output it looks like the preference alertdialog including the timepicker is fit vertically on the screen, thus leaving too little vertical space inside the dialog for the timepicker widget. Possible solutions:
In case of just a few missing dp's vertical space in the dialog, wrapping the
<TimePicker>
in a<ScrollView>
.Scaling the TimePicker down using the XML
android:scaleX
andandroid:scaleY
properties (How to make the TimePicker smaller). I am currently testing this.Setting the app full screen / immersive might help because it increases the 'available height'.
Setting the TimePicker widget to 'spinner' mode,
android:timePickerMode="spinner"
Edit: The scaleX, scaleY solution is functional, but the TimePicker looks ugly. Setting the app as full screen removes on screen UI controls, which may not be the best choice for many apps. Wrapping the timepicker in a scrollview is not optimal either.
I made two XML TimePicker layouts, one with
android:timePickerMode="spinner"
, the other with "clock". The clock layout is selected using the resource qualifier (suffix in the folder name) for available screen height: "h360dp". So that the clock is only showing when the device's available screen height, in the current orientation, excluding on-screen UI controls, is greater than 360dp. Not optimal either, but it works.Edit 2: The approach described below is better. Tested and works on real devices from Android 4 until 7. The TimePicker dialog is properly showing in landscape orientation.
Steps are:
Preference
item in the preferences xml fileTimePickerDialog
like described in the 'Pickers' guide https://developer.android.com/guide/topics/ui/controls/pickers.htmlI put example code of all code files involved here on Stackoverflow: Appcompatactivity with custom native (not compatibility) dialogpreference containing a TimePicker