Change DatePicker header text color - android

I have a datepicker that's showing a header on Lollipop, it looks like this
I want to either change the color of the big date in the header from black to white, or remove the header altogether, I don't care which. I've tried changing textColorPrimary, textColor and titleTextColor but it has no effect.

Well I have no clue what's the parent theme that you have for your Date Picker theme. Let's say you have a custom theme for your Date Picker like below,
<style name="yourCustomStyle" parent="Theme.AppCompat.Light">
Now Ctrl + click on Theme.AppCompat.Light which leads you to a new way ;) where you can find what you are looking for meaning here your issue is only about the head text but you might wish to change another views color, so that's the place you need to have a look.
And as the answer create a custom theme like below and add this attribute with the color you like
android:textColorPrimaryInverse
should do the trick for you.
<style name="yourCustomStyle" parent="Theme.AppCompat.Light">
<item name="colorAccent">#color/blue</item>
<item name="android:textColorPrimaryInverse">#color/yellow</item>
.. other
</style>
Feel free to use your own colors and code(I copied code from this) and it will do the job!
new DatePickerDialog(MainActivity.this, R.style.yourCustomStyle, new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
}
}, 2015, 02, 26).show();
Image : android:textColorPrimaryInverse with Theme.AppCompat.Dialog

I am able to change the date color in the header giving a custom theme CustomDatePickerDialogTheme to my datePicker DialogFragment:
<style name="CustomDatePickerDialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:datePickerStyle">#style/CustomDatePickerStyle</item>
</style>
<style name="CustomDatePickerStyle" parent="#android:style/Widget.Material.Light.DatePicker">
<item name="android:headerMonthTextAppearance">#style/HeaderTextStyle</item>
</style>
<style name="HeaderTextStyle" parent="#android:style/TextAppearance.Medium">
<item name="android:textColor">#color/colorAccent</item>
</style>

You can change your DateTimePicker Header and Body Background by following these steps :
go to android/app/src/main/res/values/styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColor">#000000</item>
**Add these two files !!!**
<item name="android:timePickerDialogTheme">#style/ClockTimePickerDialog</item>
<item name="android:datePickerDialogTheme">#style/DialogDatePicker.Theme</item>
</style>
**Add these files also**
<style name="DialogDatePicker.Theme" parent="Theme.AppCompat.DayNight.Dialog">
<item name="colorAccent">#000000</item>
</style>
<style name="ClockTimePickerDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#000000</item>
<item name="android:textColorPrimary">#000</item>
</style>

Kotlin, 2021
// set date as button text if pressed
btnDate.setOnClickListener(View.OnClickListener {
val dpd = DatePickerDialog(
this,
{ view, year, monthOfYear, dayOfMonth ->
val selectDate = Calendar.getInstance()
selectDate.set(Calendar.YEAR, year)
selectDate.set(Calendar.MONTH, monthOfYear)
selectDate.set(Calendar.DAY_OF_MONTH, dayOfMonth)
var formatDate = SimpleDateFormat("dd/MM/yyyy", Locale.getDefault())
val date = formatDate.format(selectDate.time)
Toast.makeText(this, date, Toast.LENGTH_SHORT).show()
btnDate.text = date
}, 1990, 6, 6
)
val calendar = Calendar.getInstance()
val year = calendar[Calendar.YEAR]
val month = calendar[Calendar.MONTH]
val day = calendar[Calendar.DAY_OF_MONTH]
dpd.datePicker.minDate = GregorianCalendar(year - 90, month, day, 0, 0).timeInMillis
dpd.datePicker.maxDate = GregorianCalendar(year - 10, month, day, 0, 0).timeInMillis
dpd.show()
})
Styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- This is main Theme Style for your application! -->
<item name="android:datePickerDialogTheme">#style/MyDatePickerDialogTheme</item>
</style>
<style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Dialog">
<item name="android:datePickerStyle">#style/MyDatePickerStyle</item>
</style>
<style name="MyDatePickerStyle" parent="#android:style/Widget.Material.DatePicker">
<item name="android:headerBackground">#A500FF</item>
</style>

Try this, it might help you:
Edit your styles.xml as:
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/white</item>
</style>
And add below lines to your code:
new DatePickerDialog(MainActivity.this, R.style.DialogTheme, new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
//DO SOMETHING
}
}, 2015, 02, 26).show();

Related

How fix color bottom panel DatePickerDialog

Color bottom panel DatePickerDialog white color.
Need set custom color
my style
<style name="DefaultTheme.DatePicker" parent="#android:style/Widget.Material.Light.DatePicker">
<item name="android:headerBackground">#FF00C853</item>
<item name="android:background">#FF000000</item>
<item name="android:calendarTextColor">#000000</item>
<item name="android:yearListSelectorColor">#000000</item>
<item name="android:datePickerMode">calendar</item>
</style>
and use
<item name="android:datePickerStyle">#style/DefaultTheme.DatePicker</item>
now so
To set the DatePickerDialog bottom panel color, refer to this link:
Change Datepicker dialog color for Android 5.0
The three steps you need to do, in order, are:
) Override datePickerDialogTheme inside your app's base theme:
<style name="AppBaseTheme" parent="android:Theme.Material.Light">
<item name="android:datePickerDialogTheme">#style/MyDatePickerDialogTheme</item>
</style>
2.) Override colorAccent inside MyDatePickerDialogTheme
<style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog">
<item name="android:colorAccent">#color/date_picker_accent</item>
<!-- No need to override 'datePickerStyle' -->
<!-- <item name="android:datePickerStyle">#style/MyDatePickerStyle</item> -->
</style>
3.) Call it this way
DatePickerDialog dpd = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
}
}, 2015, 5, 22);
dpd.show();

Change header background of DatePickerDialog

I've got a DatePickerDialog of which I would like to change the background color of the header. I've made it so that the default background of the whole application is white but now, because of the white text in the header of the Dialog it's not visible and looks very weird.
I've tried to use many other answers from SO but no luck there, this is the style I have set up in my styles.xml
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:textSize">12dp</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="android:headerBackground">#color/colorPrimary</item>
</style>
Much appreciated!
Edit: For now, since I don't use many layouts in this app, I've fixed it by setting the background for each element to white manually. A fix would still be nice...
//Put it inside style.xml file
<style name="yourCustomStyle" parent="Theme.AppCompat.Light">
<item name="colorAccent">#color/blue</item>
<item name="android:textColorPrimaryInverse">#color/yellow</item>
.. other
</style>
//After replace below code to your code
new DatePickerDialog(MainActivity.this, R.style.yourCustomStyle, new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
}
}, 2015, 02, 26).show();
//Put it in your style.xml file
<style name="datepicker" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="android:fontFamily">#font/quicksand_regular</item>
</style>
//after below code put in your view onclickListner
public void Datepiker()
{
// Get Current Date
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(this,R.style.datepicker,
new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
txt_PickupDate_val.setText(dayOfMonth + "-" + monthOfYear + "-" + year);
// txt_PickupDate_val.setEnabled(true);
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}

EditText colors and DateDialog text

I'm currently developing an android app. I've just discovered something weird and I can't seem to remove it. There is 2 weird things happening:
First issue:
I can't seem to figure out why the "Mon, Jan 25, 2016" text is at the top of my DateDialog and if it's possible to remove? You can see the image below, to see my DateDialog.
You can also see the styling of the DateDialog below.
Second issue:
I have an EditText box and the colors of the two buttons at the buttom of the dialog, can't seem to change color. Which styling elements do I have to add or is there an easy solution for me to fix this??
Datedialog:
EditText box:
Styling:
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<!--<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>-->
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/MenuBar</item>
<item name="colorPrimaryDark">#color/ShadowMenuBar</item>
<item name="colorControlNormal">#color/ColorPrimaryDark</item>
<item name="colorControlActivated">#color/ColorPrimaryDark</item>
<item name="colorControlHighlight">#color/ColorPrimaryDark</item>
<item name="android:datePickerDialogTheme">#style/MyDatePickerDialogTheme</item>
</style>
<style name="MyDatePickerDialogTheme" parent="#style/Theme.AppCompat.Light.Dialog">
<item name="android:datePickerStyle">#style/MyDatePickerStyle</item>
<item name="android:colorAccent">#color/ColorPrimaryDark</item>
<item name="colorAccent">#color/ColorPrimaryDark</item>
</style>
<style name="MyDatePickerStyle" parent="#android:style/Widget.Material.Light.DatePicker">
<item name="android:headerBackground">#color/ColorPrimaryDark</item>
<item name="android:calendarTextColor">#color/ColorPrimaryDark</item>
<item name="android:dayOfWeekBackground">#color/ColorPrimaryDark</item>
<item name="android:yearListSelectorColor">#color/ColorPrimaryDark</item>
<item name="android:datePickerMode">calendar</item>
</style>
DateDialog creation code:
private void setDateTimeField() {
Date.setOnClickListener(this);
Calendar newCalendar = Calendar.getInstance();
DateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
if(view.isShown())
{
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
}
}
},newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
}

Android: How to change DatePickerDialog colors in Theme.Holo.Light.Dialog.MinWidth?

I'm using Api 14 and the only way i found to hide the calendar view from my DataPickerDialog is using Theme.Holo.Light.Dialog.MinWidth when I create it.
But now i'm not able to change the colors of text and header.
Image of DatePickerDialog
How to change the blue color and the ok/cancel buttons?
Code of styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/backtext</item>
<!-- Customize your theme here. -->
</style>
<style name="DatePickerTheme" parent="#android:style/Theme.Holo.Light.Dialog.MinWidth">
<item name="colorAccent">#color/border</item>
<item name="android:headerBackground">#color/border</item>
<item name="android:textColorHighlight">#color/backtext</item>
</style>
DatePickerDialog creation code:
private void InitDatePicker() {
Calendar newCalendar = Calendar.getInstance();
//android.R.style.Theme_Holo_Dialog_MinWidth
//
datePickerDialog = new DatePickerDialog(this, R.style.DatePickerTheme,new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
dtVenc.setText(new SimpleDateFormat().format(newDate.getTime()));
}
}, newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
HideDayButton(datePickerDialog.getDatePicker());
datePickerDialog.setTitle("Vencimento");
}
try this
you should use headerBackground instead android:headerBackground and same for android:textColorHighlight remove android
this should work
You can try this way
<style name="abirStyle" parent="#android:style/Theme.Holo.Light.Dialog.NoActionBar">
<item name="android:textColor">#color/colorPrimary</item>
<item name="android:background">#null</item>
<item name="android:textColorPrimary">#color/colorPrimary</item>
</style>
You can try this way
<style name="abirStyle" parent="#android:style/Theme.Holo.Light.Dialog.NoActionBar">
<item name="android:textColor">#color/colorPrimary</item>
<item name="android:background">#null</item>
<item name="android:textColorPrimary">#color/colorPrimary</item>

How to change the style of a DatePicker in android?

I want to change the default color of the date/time picker dialog in Android, so that it should match my app's theme. I searched for the solution on Google, but I couldn't find a solution.
What I was doing was creating a new style:
<style name="datepicker" parent="#android:style/Widget.DeviceDefault.DatePicker">
<!---TODO-->
<item name="android:focusedMonthDateColor">#android:color/holo_red_dark</item>
</style>
Don't know what are the attributes available for date picker dialogue. It would be great if anyone could post a link on that
and after adding the style I was calling it in my main style as
<item name="android:datePickerStyle">#style/datepicker</item>
Unfortunately, this didn't work for me at all.
call like this
button5.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
DialogFragment dialogfragment = new DatePickerDialogTheme();
dialogfragment.show(getFragmentManager(), "Theme");
}
});
public static class DatePickerDialogTheme extends DialogFragment implements DatePickerDialog.OnDateSetListener{
#Override
public Dialog onCreateDialog(Bundle savedInstanceState){
final Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
//for one
//for two
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_DEVICE_DEFAULT_DARK,this,year,month,day);
//for three
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_DEVICE_DEFAULT_LIGHT,this,year,month,day);
// for four
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_HOLO_DARK,this,year,month,day);
//for five
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_HOLO_LIGHT,this,year,month,day);
//for six
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_TRADITIONAL,this,year,month,day);
return datepickerdialog;
}
public void onDateSet(DatePicker view, int year, int month, int day){
TextView textview = (TextView)getActivity().findViewById(R.id.textView1);
textview.setText(day + ":" + (month+1) + ":" + year);
}
}
follow this it will give you all type date picker style(copy from this)
http://www.android-examples.com/change-datepickerdialog-theme-in-android-using-dialogfragment/
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>
To change DatePicker colors (calendar mode) at application level define below properties.
<style name="MyAppTheme" parent="Theme.AppCompat.Light">
<item name="colorAccent">#ff6d00</item>
<item name="colorControlActivated">#33691e</item>
<item name="android:selectableItemBackgroundBorderless">#color/colorPrimaryDark</item>
<item name="colorControlHighlight">#d50000</item>
</style>
See http://www.zoftino.com/android-datepicker-example for other DatePicker custom styles
Create a new style
<style name="my_dialog_theme" parent="ThemeOverlay.AppCompat.Dialog">
<item name="colorAccent">#color/colorAccent</item> <!--header background-->
<item name="android:windowBackground">#color/colorPrimary</item> <!--calendar background-->
<item name="android:colorControlActivated">#color/colorAccent</item> <!--selected day-->
<item name="android:textColorPrimary">#color/colorPrimaryText</item> <!--days of the month-->
<item name="android:textColorSecondary">#color/colorAccent</item> <!--days of the week-->
</style>
Then initialize the dialog
Calendar mCalendar = new GregorianCalendar();
mCalendar.setTime(new Date());
new DatePickerDialog(mContext, R.style.my_dialog_theme, new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
//do something with the date
}
}, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH)).show();
Result:
Calendar calendar = Calendar.getInstance();
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), R.style.DatePickerDialogTheme, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
String date = simpleDateFormat.format(newDate.getTime());
}
}, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
datePickerDialog.show();
And use this style:
<style name="DatePickerDialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/colorPrimary</item>
</style>
Create custom DatePickerDialog style:
<style name="AppTheme.DatePickerDialog" parent="Theme.MaterialComponents.Light.Dialog">
<item name="android:colorAccent">#color/colorPrimary</item>
<item name="android:colorControlActivated">#color/colorPrimaryDark</item>
<item name="android:buttonBarPositiveButtonStyle">#style/AppTheme.Alert.Button.Positive</item>
<item name="android:buttonBarNegativeButtonStyle">#style/AppTheme.Alert.Button.Negative</item>
<item name="android:buttonBarNeutralButtonStyle">#style/AppTheme.Alert.Button.Neutral</item>
</style>
<style name="AppTheme.Alert.Button.Positive" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:textColor">#color/buttonPositive</item>
</style>
<style name="AppTheme.Alert.Button.Negative" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:textColor">#color/buttonNegative</item>
</style>
<style name="AppTheme.Alert.Button.Neutral" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:textColor">#color/buttonNeutral</item>
</style>
Set custom datePickerDialogTheme style in app theme:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:datePickerDialogTheme">#style/AppTheme.DatePickerDialog</item>
</style>
Set theme programmatically on initialization like this:
val datetime = DatePickerDialog(this, R.style.AppTheme_DatePickerDialog)
(I'm using React Native; targetSdkVersion 22). I'm trying to change the look of a calendar date picker dialog. The accepted answer didn't work for me, but this did. Hope this snippet helps some of you.
<style name="CalendarDatePickerDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#6bf442</item>
<item name="android:textColorPrimary">#6bf442</item>
</style>
As AlertDialog.THEME attributes are deprecated, while creating DatePickerDialog you should pass one of these parameters for int themeResId
android.R.style.Theme_DeviceDefault_Dialog_Alert
android.R.style.Theme_DeviceDefault_Light_Dialog_Alert
android.R.style.Theme_Material_Light_Dialog_Alert
android.R.style.Theme_Material_Dialog_Alert
For DayNight theme:
Create theme for date/time picker:
<style name="App.Dialog.DateTime" parent="Theme.AppCompat.DayNight.Dialog">
<item name="colorAccent">?attr/clAccent</item>
<item name="android:windowBackground">?attr/clPrimary</item>
<item name="android:buttonBarNegativeButtonStyle">#style/App.Dialog.NegativeButton</item>
<!-- For overScrollMode -->
<item name="android:colorEdgeEffect">?attr/clAccentRipple</item>
<item name="android:overScrollMode">ifContentScrolls</item>
</style>
<style name="App.Dialog.NegativeButton" parent="#style/Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">?attr/clContentSecond</item>
</style>
You may specify styles for different dialog buttons (like I did it via App.Dialog.NegativeButton)
Also, I tried another parent theme (for App.Dialog.DateTime): Theme.AppCompat.DayNight.Dialog.Alert, but result looked ugly with strange dialog window sizes.
Setup date/time picker theme inside your app theme:
<item name="android:datePickerDialogTheme">#style/App.Dialog.DateTime</item>
<item name="android:timePickerDialogTheme">#style/App.Dialog.DateTime</item>
The result:
For more dialog customization you may check xml keys from this answer.
If you are using a DatePicker in XML, all you have to do is adding a style for your dialog as #theBeardedPilot mentioned like this:
<style name="DialogTheme" parent="ThemeOverlay.AppCompat.Dialog">
<!--header background-->
<item name="colorAccent">#android:color/holo_green_dark</item>
<!--selected day-->
<item name="android:colorControlActivated">#android:color/holo_red_dark</item>
<!--days of the month-->
<item name="android:textColorPrimary">#android:color/holo_orange_dark</item>
<!--days of the week-->
<item name="android:textColorSecondary">#android:color/holo_blue_dark</item>
</style>
then call this style using the android:theme attribute like this:
<DatePicker
android:theme="#style/DialogTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

Categories

Resources