Thursday, August 27, 2015

How to create a DatePicker without calendar in Android

activity_main.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    tools:context=".MainActivity"
    android:background="#d8dcda"
    >
    <!--
        android:calendarViewShown
            Whether the calendar view is shown. Only valid for "spinner" mode.
            Must be a boolean value, either "true" or "false".

            This may also be a reference to a resource (in the form "@[package:]type:name")
            or theme attribute (in the form "?[package:][type:]name")
            containing a value of this type.
            This corresponds to the global attribute resource symbol calendarViewShown.

        android:datePickerMode
            Defines the look of the widget. Prior to the L release, the only choice was
            spinner. As of L, with the Material theme selected, the default layout is
            calendar, but this attribute can be used to force spinner to be used instead.

            Must be one of the following constant values.
            spinner : Date picker with spinner controls to select the date.
            calendar : Date picker with calendar to select the date.

            This corresponds to the global attribute resource symbol datePickerMode.
    -->
    <DatePicker
        android:id="@+id/dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:calendarViewShown="false"
        android:datePickerMode="spinner"
        />
</RelativeLayout>
More android examples