Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] DatePicker theming issues with Android dark mode #9033

Closed
streviranus opened this issue Dec 27, 2019 · 61 comments · Fixed by #14591
Closed

[Bug] DatePicker theming issues with Android dark mode #9033

streviranus opened this issue Dec 27, 2019 · 61 comments · Fixed by #14591

Comments

@streviranus
Copy link

Description

When using an Android device that supports dark mode (i.e. Android 10) and styles inheriting from Theme.AppCompat.DayNight, the DatePicker dialog box has a white background instead of dark gray when the device is in dark mode, resulting in unreadable text.

Related to: (#8029)

Steps to Reproduce

  1. Define a theme in your Android project that inherits from Theme.AppCompat.DayNight
  2. Make a datepicker theme that inherits from Theme.AppCompat.DayNight.Dialog
  3. Add the datepicker dialog style to the application theme like so:
    @style/AppCompatDialogStyle
  4. Set the theme of your MainActivity to the application theme defined above.
  5. Run the app on a device in dark mode and click on a DatePicker

Expected Behavior

The DatePicker is styled according to the theme, with white text on a dark background.

Actual Behavior

The DatePicker style is only partially applied, resulting in white text on a white background.

Basic Information

  • Version with issue: 4.4.0
  • Last known good version: Unknown
  • IDE: Visual Studio Professional 2019, version 16.4.2
  • Platform Target Frameworks:
    • Android: 10.0
  • Android Support Library Version: 28.0.0.3
  • Affected Devices: Pixel 2 with Android 10.0

Screenshots

Screenshot_20191227-151204
Screenshot_20191227-151031

Reproduction Link

DisplayAlertTheming 2.zip

@streviranus streviranus added s/unverified New report that has yet to be verified t/bug 🐛 labels Dec 27, 2019
@kingces95
Copy link
Contributor

Investigating

@jfversluis
Copy link
Member

Same seems to happen to the normal picker dialog. Also in the Gallery app. But only when you apply customizations. If you take out the custom styles in the styles.xml everything will fall in line.

@samhouts samhouts added e/3 🕒 3 and removed s/unverified New report that has yet to be verified labels Feb 1, 2020
@DennisWelu
Copy link

Related to Jan6 comment by @jfversluis, removing this line from "styles.xml" cleared up the problem with the "blank" date picker.

<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>

@MathewLC
Copy link
Contributor

MathewLC commented May 7, 2020

@jfversluis normal picker has this problem too with the dialog. You guys have plan on fixing? Should I open another issue for that? I'm didn't found any other open about this.

@jfversluis
Copy link
Member

jfversluis commented May 7, 2020

No need for a new issue! It’s clear that this happens for all the picker variations. We’re aware and hopefully get around to this soon

If you have any additional information on a possible fix or cause that would be very welcome though

@MathewLC
Copy link
Contributor

MathewLC commented May 8, 2020

I didn't spent too much time looking at it, but I'll definitely do it soon and if I found something I'll let you guys know. Best Regards.

@sebfrie
Copy link

sebfrie commented Aug 7, 2020

Are there any updates on this one? A fix is highly appreciated.

@samhouts samhouts added this to the 5.0.0 milestone Aug 13, 2020
@samhouts samhouts removed this from the 5.0.0 milestone Nov 2, 2020
@kazo0
Copy link
Contributor

kazo0 commented Nov 3, 2020

Is there currently a workaround for this to get the DatePicker dialog to properly show in dark mode?

@stefanbogaard86
Copy link

Is there currently a workaround for this to get the DatePicker dialog to properly show in dark mode?

The workaround I used was to add the Xamarin.Forms.Visual.Material package to my project and set the Visual property to "Material" on my datepickers.

@BurkusCat
Copy link
Contributor

BurkusCat commented Dec 26, 2020

When trying to use as spinner datepicker in DayNight mode, a similar issue occurs in Dark mode:
image

    <item name="android:datePickerDialogTheme">@style/SpinnerDatePickerStyle</item>
  </style>
    
  <style name="SpinnerDatePickerStyle" parent="Theme.AppCompat.DayNight.Dialog">
    <item name="android:datePickerStyle">@style/SpinnerDatePicker</item>
  </style>

  <style name="SpinnerDatePicker" parent="android:Widget.Material.DatePicker">
      <item name="android:datePickerMode">spinner</item>
  </style>

@daniel-leinweber
Copy link

daniel-leinweber commented Oct 4, 2021

The nightly feed with Xamarin.Forms version 5.0.1.1876 does not fix the issue for me.

I did not include prereleases at first. Unfortunately it is still not solved in version 5.0.1.2031-nightly

@jfversluis
Copy link
Member

I see the nightly didn't run correctly over the weekend, sorry about that. Looking into it now :)

@jfversluis
Copy link
Member

Could you try 5.0.0.2151 from the nightly feed (note, no nightly suffix) please? :)

@daniel-leinweber
Copy link

The version you mention is not available to me. I guess you meant 5.0.1.2151 and not 5.0.0.2151.

Do I need to add a different package source than https://aka.ms/xf-ci/index.json?

@jfversluis
Copy link
Member

Interesting. There is more than one nightly feed it's pushed to 😅 It's Monday, sorry! Let me dig a bit deeper.

@jfversluis
Copy link
Member

Hey there! Could you try this feed please? :)

@daniel-leinweber
Copy link

Awesome, that worked for me.

I have now installed version 5.0.0.2154-nightly.

Screenshot_20211008-141749.jpg

@jfversluis
Copy link
Member

YAY YAY YAY! Thanks for confirming! This will be in the next Service Release that should be out next week if everything goes well :)

@Jorel254
Copy link

Jorel254 commented Oct 9, 2021

@daniel-leinweber Hello, Could you show me the style you implemented to change the datepicker background color?
I tried the nightly build without luck.
Best regards

@jfversluis
Copy link
Member

@Jorel254 let's try the other way around; what is styles you have? :D

I had to remove this to make it work: https://github.com/xamarin/Xamarin.Forms/pull/14591/files#diff-ad6ba5549da76edd8ee1934f53d44907391c58a5c8fa7071b8fd7a7e47408c9aL49

@daniel-leinweber
Copy link

@daniel-leinweber Hello, Could you show me the style you implemented to change the datepicker background color? I tried the nightly build without luck. Best regards

Sure. I use a custom control that extends the DatePicker by a "NullableDate" Property. Everything else is inherited.

NullableDatePicker

<controls:NullableDatePicker
    x:Name="EndDatePicker"
    Format="dd.MM.yyyy"
    MinimumDate="{Binding Source={x:Reference StartDatePicker}, Path=NullableDate}"
    Visual="Material"
    BackgroundColor="{AppThemeBinding 
        Light={StaticResource LightEntryBackgroundColor}, 
        Dark={StaticResource DarkEntryBackgroundColor}}"
    TextColor="{AppThemeBinding 
        Light={StaticResource LightPrimaryTextColor}, 
        Dark={StaticResource DarkPrimaryTextColor}}"
    NullableDate="{Binding EndDate}"/>

For the BackgroundColor and the TextColor I use AppThemeBinding to define a color for either Light or Dark, but I have not changed any colors of the actual Popup. I think they are derived from the standard colors of the Android Project.

@Jon2G
Copy link
Contributor

Jon2G commented Oct 10, 2021

@Jorel254 @jfversluis @daniel-leinweber

Our team just tested both ways. I can confirm this is working.
I appreciate the time you took to help me with this issue.
However, the time picker appears to have the same theming issue
¿Should we create a new ticket about time picker?
I'm much obliged
image

@Jorel254
Copy link

@daniel-leinweber, @jfversluis
I appreciate the time you took to help me with this issue.
I'm much obliged.

@jfversluis
Copy link
Member

@Jorel254 @Jon2G My pleasure!

I think the picker should have worked as well. But from what I understand the picker still shows this problem? Also with this NuGet? Could you provide a reproduction case?

@Jon2G
Copy link
Contributor

Jon2G commented Oct 11, 2021

Of course:
https://github.com/Jon2G/Xamarin-9033
While making this reproduction I noticed the problem is that the accent color remains to be hotpink even after changing it on styles.xml.
Maybe I'm missing something

@sammacdougall
Copy link

I used this and it has reverted to pink accent on the dialog.
I have after much experimentation found a solution to this. I have added a values-night folder to android resources and added a style sheet in here.
With in the style sheet I have added my styling for night mode.
I have added my code for light mode in the default style sheet under the values folder.
If there is a site to share this info others may be interested.
Night mode code below in style sheet.

<style name="Theme.Splash" parent="android:Theme"> @xml/splash_screen_night true </style> <style name="MainTheme" parent="MainTheme.Base"> #2196F3 @style/CustomDatePickerDialog </style> <style name="CustomDatePickerDialog" parent="ThemeOverlay.AppCompat.Dialog"> #2196F3 #FFFFFF #292929 #2196F3 #FFFFFF/item> #FFFFFF #2196F3 </style>

(edited)

@mos379
Copy link

mos379 commented Oct 21, 2021

@sammacdougall that's what I did too long time ago but I can't remember why that is not the best solution.

@sammacdougall
Copy link

sammacdougall commented Oct 21, 2021 via email

@mina5500
Copy link

Issue fixed with appcompat theme ... but issue with ok cancel colors always pink ... was able to set colors before.
However it does not work with material theme ... white background unreadable popup
@jfversluis

@jfversluis
Copy link
Member

Please open an issue if something is still not right with all the details you can get. Screenshots, and preferably a reproduction showing the issue. Thanks!

@mos379
Copy link

mos379 commented Oct 22, 2021

@sammacdougall
I'm pretty sure I did it with this one in my values-night scheme

<style name="AppCompatDialogStyle" parent="Theme.AppCompat.DayNight.Dialog">
    <item name="colorAccent">@color/colorAccent</item>
  </style>

@meta-byte
Copy link

meta-byte commented Oct 26, 2021

Screenshot_20211025-223013

Currently using dark theme (Android 11)
Xamarin version 5.0.0.2196
NO custom styling applied to themes. Only styling has been done to elements

Reproduced it here as well: XamarinForms-9033
This is a default Flyout app. The button on the about page has been changed to a date picker.

@jfversluis
Copy link
Member

jfversluis commented Oct 26, 2021

While building your reproduction I noticed this in the output

Detected package downgrade: Xamarin.Essentials from 1.7.0 to 1.6.1. Reference the package directly from the project to select a different version.
XamarinForms_9033.Android -> XamarinForms_9033 -> Xamarin.Essentials (>= 1.7.0)
XamarinForms_9033.Android -> Xamarin.Essentials (>= 1.6.1)
Detected package downgrade: Xamarin.Forms from 5.0.0.2196 to 5.0.0.2012. Reference the package directly from the project to select a different version.
XamarinForms_9033.Android -> XamarinForms_9033 -> Xamarin.Forms (>= 5.0.0.2196)
XamarinForms_9033.Android -> Xamarin.Forms (>= 5.0.0.2012)

Meaning, not all packages were in sync for all projects. After updating all and rebuilding, it works correctly.

@mina5500
Copy link

mina5500 commented Oct 26, 2021

i have the same issue i used the same project in original issue up and it is not working
can you please help @jfversluis
image
image

DisplayAlertTheming 2.zip

@jfversluis

@jfversluis
Copy link
Member

@mina5500 please never paste code as a screenshot and always as text. I won't type it all over from an image :)

<style name="AppCompatDialogStyle" parent="Theme.AppCompat.DayNight.Dialog.Alert">
  <item name="colorAccent">#FF0000</item>
</style>

remove the parent attribute from this to make it work. Or, if you don't need this at all remove the whole entry as well as references to it.

@mina5500
Copy link

@jfversluis i already uploaded the whole project as zip file .. the screenshot was just for quick look :)

@mina5500
Copy link

mina5500 commented Oct 26, 2021

i am confirming that it is working fine on sample solution
thanks @jfversluis 👍

image

but in my production project i am using

  <style name="MainTheme" parent="MainTheme.Base">
    <item name="android:windowBackground">@xml/splash_screen</item>
  </style>

which causes the backgroud to mess up

image

this was working fine in earlier versions of XF
any ideas ? @jfversluis

Update i added parent and it fixed my issue 😊 @jfversluis

  <style name="AppCompatDialogStyle" parent="Theme.AppCompat.DayNight">
    <item name="colorAccent">#29aae3</item>
  </style>

image

@meta-byte
Copy link

While building your reproduction I noticed this in the output

Detected package downgrade: Xamarin.Essentials from 1.7.0 to 1.6.1. Reference the package directly from the project to select a different version.
XamarinForms_9033.Android -> XamarinForms_9033 -> Xamarin.Essentials (>= 1.7.0)
XamarinForms_9033.Android -> Xamarin.Essentials (>= 1.6.1)
Detected package downgrade: Xamarin.Forms from 5.0.0.2196 to 5.0.0.2012. Reference the package directly from the project to select a different version.
XamarinForms_9033.Android -> XamarinForms_9033 -> Xamarin.Forms (>= 5.0.0.2196)
XamarinForms_9033.Android -> Xamarin.Forms (>= 5.0.0.2012)

Meaning, not all packages were in sync for all projects. After updating all and rebuilding, it works correctly.

Thanks for pointing it out! Completely missed that.

High5Apps added a commit to High5Apps/organize-rn that referenced this issue Nov 8, 2023
- Needed to set the styles.xml colorAccent in order to affecting the picker theme accent color on Android
  - Initial advice from: mmazzarolo/react-native-modal-datetime-picker#106 (comment)
  - Actual solution inspired by: xamarin/Xamarin.Forms#9033 (comment)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.