Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android date/time wheel picker

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.

enter image description here

like image 742
Amos Avatar asked Apr 06 '15 11:04

Amos


3 Answers

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.

like image 174
Rodrigo Borges Avatar answered Nov 18 '22 03:11

Rodrigo Borges


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:

Date Time Picker Example

like image 31
madfree Avatar answered Nov 18 '22 04:11

madfree


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.

like image 33
Busata Avatar answered Nov 18 '22 03:11

Busata