How to Change the Style of a Datepicker in Android

How to change the style of a DatePicker in android?

Try this. It's the easiest & most efficient way

<style name="datepicker" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/primary</item>
</style>

Change date-picker text color in spinner mode in android?

You can use:

<DatePicker
android:theme="@style/MyDatePicker"
..>

with:

<style name="MyDatePicker" >
<!-- Text color -->
<item name="android:textColorPrimary">@color/....</item>
<!-- Divider color -->
<item name="colorControlNormal">@color/...</item>
</style>

Sample Image

Change Date picker dialog theme

try as below

 Button btn_ok = alert.getButton(DialogInterface.BUTTON_POSITIVE);
btn_ok .setBackgroundColor(Color.YELLOW); //add your color

Change fontcolor of DatePicker Android

EDIT2: This works. (Added divider color)

Your XML

<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/datePicker"
android:calendarViewShown="false"
android:spinnersShown="true"
android:datePickerMode="spinner"
android:layout_below="@+id/tb_register_last_name"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/bt_register_tostep3"
android:layout_alignEnd="@+id/bt_register_tostep3"
android:theme="@style/MyDatePicker"/>

In styles.xml, set this (copy-paste the code)

<style name="MyDatePicker" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorControlNormal">#00FF00</item>
<item name="colorControlActivated">#00FF00</item>
<item name="android:textColorPrimary">#FF0000</item>
</style>

Google materialdoc will be helpful for you in the future.

Change your style and let me know if it works!!

How to change the style from DatePicker and TimePicker programmatically in Android?

I've found my own answer and it is quite simple. When instaciating the TimePicker and DatePicker send as parameter a new ContextThemeWrapper with the custom style you want in order to change the style.

Style.xml

<style name="CustomPickerTheme">
<item name="colorAccent">@color/Red</item>
</style>

MainActivity.class

TimePicker timePicker = new TimePicker(new ContextThemeWrapper(MainActivity.this, R.style.CustomPickerTheme));
DatePicker datePicker = new DatePicker(new ContextThemeWrapper(MainActivity.this, R.style.CustomPickerTheme));


Related Topics



Leave a reply



Submit