Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change the Datepicker style for Android

I'm currently making a registration form, and one of the fields is for the users Date of Birth. I want to use datepicker, however I don't want the calendar layout as shown below:

enter image description here

I want the layout to look something like this so that way its easier to choose the year and month without having to scroll through everything:

enter image description here

However I do not know how to go about this, or what to put inside the styles.xml file. Any help would be greatly appreciated.

like image 827
JulianMartinez23 Avatar asked Sep 10 '16 19:09

JulianMartinez23


People also ask

How can I change DatePicker size in android?

For example, android:layout_width="15dp" will set the width at a scalable value of 15. You can change 15 to whatever you want. If you want to set a specific pixel size, you can use, for example, 15px .


2 Answers

Add this to style.xml

<style name="date_picker_theme" parent="@android:style/Widget.DatePicker">

And then you should apply style for your date picker like this:

<DatePicker
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/datePicker"
        style="@style/date_picker_theme" />
like image 180
Victor V. Avatar answered Oct 21 '22 12:10

Victor V.


Create style with

<style name="DatePicker" parent="@android:style/Theme.Holo.Light">
    <item name="android:datePickerStyle">@android:style/Widget.DatePicker</item>
</style>

Then in custom fragment dialog xml

<DatePicker
    android:theme="@style/DatePicker"
    android:id="@+id/fragment_date_picker_control"
    android:datePickerMode="spinner"
    android:spinnersShown="true"
    android:calendarViewShown="false"
    android:layout_marginLeft="@dimen/margin_normal"
    android:layout_marginRight="@dimen/margin_normal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal" />

Link : http://yogeshkalwar.blogspot.in/2017/08/custom-spinner-datepicker-supporting-n70.html

like image 40
yogikalwar Avatar answered Oct 21 '22 12:10

yogikalwar