In my Android project currently under development, there are many Fragments in Activity. And inside the Fragment, RecyclerView is used to show multiple Items to the user.
What I want is that when the user changes the dark mode or light mode in the status bar, the dark mode is applied without exiting the app. What should I do?
Given a
Configuration
, you can find out whether the device is in dark mode by examininguiMode
:(source code from the documentation)
You can get a
Configuration
:uiMode
in the manifest and overridingonConfigurationChanged()
in your activity, orgetResources().getConfiguration()
on aContext
, such as yourActivity