I am struggling to solve this error that happens only when I am on night mode (I am using Theme.MaterialComponents.DayNight) and when rotating the screen... on day mode it works fine with no issues.
Attempt to read from field 'float android.content.res.Configuration.fontScale' on a null object reference
I have no idea where it is coming from, I am not using any custom fonts.
To turn off the Dark Mode in Windows 10, open Settings and go to Personalization. On the left column, choose Colors, and then select the following options: In the "Choose your color" dropdown list, choose Custom. Under "Choose your default Windows mode," select Dark.
On your phone, open the Settings app. Tap Display. Turn Dark theme on or off.
Disable all over the app: AppCompatDelegate. setDefaultNightMode(AppCompatDelegate. MODE_NIGHT_NO)
Since Nov. 21, 2019 some Samsung Galaxy devices repeatedly switch back to day mode. This not an issue with the Dark Mode app but with the Email app by Samsung. The Samsung Email app overwrites the Android night mode settings which may switch your device back to day mode.
I have experienced the same issue when I call AppCompatDelegate.setDefaultNightMode
from the main activity's onCreate
.
My workaround is simple: call it from a fragment's onCreateView
.
I can't explain why this works but it just works for me.
(Updated 2/4/20) Please see Jason Marks' answer, which works better than mine.
Try calling AppCompatDelegate.setDefaultNightMode() before super.onCreate(...) in your Activity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With