I obtain a warning in Android Studio upon using the setCurrentHour Method (as below), that it has been deprecated.
timePicker.setCurrentHour(hour);
Meanwhile, upon using the setHour Method (as hereafter), I obtain a warning stating that the "Call requires API level 23" while the current minimum is lower.
timePicker.setHour(hour);
Is there a Support Library that I could use for Backward Compatibility, avoiding thus any warnings?
android.widget.TimePicker. A widget for selecting the time of day, in either 24-hour or AM/PM mode. For a dialog using this view, see TimePickerDialog .
I'm not sure if there is already a support library for this, but this is what I've done when I was dealing with these methods:
Java:
private void setTime(int hour, int minute) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mTimePicker.setHour(hour);
mTimePicker.setMinute(minute);
} else {
mTimePicker.setCurrentHour(hour);
mTimePicker.setCurrentMinute(minute);
}
}
And in Kotlin:
private fun setTime(hours: Int, minutes: Int) {
@Suppress("DEPRECATION")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
time_picker.hour = hours
time_picker.minute = minutes
} else {
time_picker.currentHour = hours
time_picker.currentMinute = minutes
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With