The inbox app features a navigation drawer. Upon clicking on any navigation drawer item a fragment is loaded (most probably) and during this transaction the app theme changes. Changing app theme requires setTheme() method to be called before setContentView(..) in the onCreate() method of the activity. The super fluid UI indicate the use of fragments so how is this achieved without recreating parent activity (otherwise there would have been a lag for sure).
Asked
Active
Viewed 98 times
0
-
please explain your question first – Adam Feb 23 '18 at 12:42
-
Do you get my question now? – Nitin Tapria Feb 23 '18 at 13:22
-
Yes, and this could easily be implemented using https://stackoverflow.com/a/2483001/5928383 only trick here is, it works with Activities. since you have fragments way around is to add a restartActivity method with fragment change keeping record of current fragment. otherwise implement it using activities. – Adam Feb 26 '18 at 05:31
2 Answers
0
You can actually change the theme's style, but only before calling setContentView(@ResId int)
method. Something like this perhaps?
getTheme().applyStyle(isDashUser ? R.style.redStatusBar : R.style.blackStatusBar, true);
setContentView(R.layout.my_activity);

Shark
- 6,513
- 3
- 28
- 50
-
This requires the onCreate() method of the activity to be invoked which means that when using fragments (like in navigation drawer), the parent activity needs to be recreated but the Inbox app do not do that otherwise there would be some lag for sure – Nitin Tapria Feb 23 '18 at 13:11
0
If you look closely when changing the page there's a slight graduation between the two colours. This probably suggests they have a system separate from theming to re-colour all the UI elements.
One my apps has a very similar colour change feature, and I just have methods set up to manually re-apply the relevant colours to each UI element. Of course Google probably have some super slick way of doing it that they'll never share with anyone.

Dan
- 321
- 3
- 11