Skip to content
Related Articles
Open in App
Not now

Related Articles

Slider Date Picker in Android

Improve Article
Save Article
  • Difficulty Level : Hard
  • Last Updated : 22 Nov, 2021
Improve Article
Save Article

Slider Date Picker is one of the most popular features that we see in most apps. We can get to see this Slider date picker in most of the travel planning applications, Ticket booking services, and many more. Using Slider date Picker makes it efficient to pick the date. In this article, we are going to see how to implement Slider Date Picker in Android. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language. 

Slider Date Picker in Android Sample GIF

Applications of Slider Date Picker

  • The most common application of this Slider date picker is it is used in most travel planning apps.
  • This Date Picker can also be seen in Ticket Booking services.
  • You can get to see this Slider Date Picker in the exam form filling application.

Attributes of Slider Date Picker



.setStartDate()To set the starting Date of the Calendar.
.setEndDate()To set the ending Date of the Calendar.
.setThemeColor()To set the theme Color.
.setHeaderTextColor()To set the header text Color.
.setHeaderDateFormat()To set the Date Format.
.setShowYear()To show the current year.
.setCancelText()To cancel text.
.setConfirmText()To confirm text.
.setPreselectedDate()To select today’s date.

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Add dependency and JitPack Repository

Navigate to the Gradle Scripts > build.gradle(Module:app) and add the below dependency in the dependencies section.   

implementation ‘com.github.niwattep:material-slide-date-picker:v2.0.0’

Add the JitPack repository to your build file. Add it to your root build.gradle at the end of repositories inside the allprojects{ } section.

allprojects {

 repositories {


   maven { url “” }



After adding this dependency sync your project and now we will move towards its implementation.  

Step 3: Create a new Slider Date Picker in your activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
    <!--Text View to display Date-->
        android:text="Text View" />
    <!--Button to select date-->
        android:text="SELECT" />

Step 4: Working with the file

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.niwattep.materialslidedatepicker.SlideDatePickerDialog;
import com.niwattep.materialslidedatepicker.SlideDatePickerDialogCallback;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
public class MainActivity extends AppCompatActivity implements SlideDatePickerDialogCallback {
    // Initialize textview and button
    Button button;
    TextView textView;
    protected void onCreate(Bundle savedInstanceState) {
        // button and text view called using id
        button = findViewById(;
        textView = findViewById(;
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Calendar endDate = Calendar.getInstance();
                endDate.set(Calendar.YEAR, 2100);
                SlideDatePickerDialog.Builder builder = new SlideDatePickerDialog.Builder();
                SlideDatePickerDialog dialog =;
      , "Dialog");
    // date picker
    public void onPositiveClick(int date, int month, int year, Calendar calendar) {
        SimpleDateFormat format = new SimpleDateFormat("EEEE, MMM dd, yyyy", Locale.getDefault());

Now click on the run option it will take some time to build Gradle. After that, you will get output on your device as given below.


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!