Night Mode effect without flickering

Night Mode effect without flickering

Night Mode effect like Zhihu and Twitter with simple implementation

Effect:

gif gif

Twitter <—> My Implemetation

What we want

Fade effect when switching theme instead of flickering the activity screen when recreate.

Pre-requisite

  • Android Support Library v7 24.2.0
  • colors-night.xml for immediate change of your layout color.

Cautious

This code does not works with Android Nougat API 24.

Talk is cheap, but here is some explanation

  1. Window Animations is the code that eliminate the flickering of recreate.
  2. Create a new style to enclose windowEnterAnimation and windowExitAnimation
  3. Define your fade in animation and fade out animation, do not let user wait too long.

Show me the code

Closing

I tried to digging around in Nougat Source Code, and still unable to find the cause. Will update if there are any findings.

If you have any suggestion on this code please comment, highly appreciate for it.

Thanks for reading.

Github

Comments