How can I achieve this layout for a time picker (and also for a date picker)? The default layout is either a (very big) clock or a (not beautiful) spinner style time picker. I saw this in several apps but couldn't find how to achieve this look and feel.
For future reference for anyone that might need this, it is possible to achieve this time picker spinner by just choosing a TimePicker among the android widgets and then, on the xml file, type android:timePickerMode="spinner"
.
Your widget xml code should look like this:
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner" />
My answer was based on the documentation.
Simplest way to achieve this in my view is since api level 21:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="8dp">
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner" />
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:datePickerMode="spinner" />
</LinearLayout>
You get this:
This example has three pickers: NumberPicker, DatePicker and TimerPicker.
https://github.com/rodrigobusata/android-pickers
or
Use only the sample without the library and override for Android default pickers.
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