If night mode is ON, I want to pick a different layout in my activity.
What I have done:
added separate layout folders for night
and notnight
as follows:
res
-----layout-night
----------my_layout.xml
-----layout-notnight
----------my_layout.xml
Now, when I toggle night mode and reopen the app, I was hoping the layout would change, but it doesn't.
Is there something extra required for this to work?
Is there a permission i need to add for this to work? If yes, which one?
Not looking for an alternate approach. My use case specifically needs a layout to be picked based on night mode status. I'm trying to figure out why the right layout doesn't get picked automatically, when the folders are in place.
UPDATE : Narrowed down problem. The layout layout-notnight
gets picked always. Hence, folder structure is working fine. App is not being able to detect the night mode. (Night mode is toggled ON on the device- tried toggling on and off it works on device but app wont detect)
So question now is:
Is a permission required for it being able to detect the state of night mode? like it needs for detecting wifi state and network state.
onCreate
usesetContentView
to select the appropriate one?mdpi
,hdpi
,xhdpi
etc. Maybe you can find out how that's being done and try to mimic that?getNightMode()
and logging the value?