Search code examples
androidandroid-datepicker

Android DatePicker layout customisation


When DatePicker is displayed with calendar view, is it possible to have additional label with some text at the bottom of this calendar view (as shown on the picture)? I've tried looking if there is a possibility to customise original Android DatePicker, can't see any suitable way of doing it.

datepicker


Solution

  • You can get the source code from here.

    In order to customize layout as you want, you should modify layout-land/mdtp_date_picker_dialog.xml and layout-sw600dp-land/mdtp_date_picker_dialog.xml fiels. Here I have added two TextViews as your screenshot:

    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/mdtp_background_color"
        android:orientation="vertical">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="450dp"
            android:gravity="center"
            android:orientation="horizontal">
    
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:orientation="vertical">
    
                <include layout="@layout/mdtp_date_picker_header_view" />
    
                <include layout="@layout/mdtp_date_picker_selected_date" />
    
                <include layout="@layout/mdtp_date_picker_footer_view" />
    
                <TextView
                    android:id="@+id/added_text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="8dp"
                    android:text="Some Text" />
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">
    
                <include layout="@layout/mdtp_date_picker_view_animator" />
    
                <TextView
                    android:id="@+id/added_text2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Some text" />
            </LinearLayout>
    
        </LinearLayout>
    
        <include layout="@layout/mdtp_done_button" />
    </LinearLayout>
    

    Change related dimens to locate the TextViews as you want.