Hide/Remove calendar from DatePicker in android using XML

How to disable calendar view inside DatePicker widget to create datepicker without calendar.

In this tutorial we are simply creating date picker widget without the calendar view because calender view occupies the whole screen and its very hard to find the year and months inside date picker while showing calendar view. So in this tutorial we are using two XML attributes on date picker to disable the calendar view that is android:calendarViewShown=”false” and android:datePickerMode=”spinner” . So here is the complete step by step tutorial for Hide/Remove calendar from DatePicker in android using XML.

android-project-download-code-button

How to Hide/Remove calendar from DatePicker in android using XML.

Code for MainActivity.java file.

package com.datepickerwithoutcalendar_android_examples.com;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.datepickerwithoutcalendar_android_examples.com.MainActivity" >

 <DatePicker
 android:id="@+id/datePicker1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:calendarViewShown="false"
 android:datePickerMode="spinner" />

</RelativeLayout>

Screenshot:

Hide/Remove calendar from DatePicker in android using XML

Click here to download Hide/Remove calendar from DatePicker in android using XML project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *