Timepickerdialog Widget In Landscape Mode (preferencescreen)
Solution 1:
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:
- Include a general
Preference
item in the preferences xml file - Set a click listener on this Preference using onPreferenceTreeClick()
- When this Preference is clicked, show a regular (not compatibility library)
TimePickerDialog
like described in the 'Pickers' guide https://developer.android.com/guide/topics/ui/controls/pickers.html - Save the time set on the TimePicker manually in the SharedPreferences
I put example code of all code files involved here on Stackoverflow: Appcompatactivity with custom native (not compatibility) dialogpreference containing a TimePicker
Post a Comment for "Timepickerdialog Widget In Landscape Mode (preferencescreen)"