Android Question Change theme via code? (Transparent bars)

alexwekell

Member
Licensed User
A lot of kitkat users are request a transparent theme for my app, and I've successfully added it, but is there anyway to change the theme after the app is running. I'd like to give people the option to turn off transparent nav bars if they want.
 

alexwekell

Member
Licensed User
What is it?
Create separate value systems for themes and create a custom theme (look around somewhere on the forum for changing values based on SDK version), so you should have values-v19 and values in res with two theme.xml files. This first step is needed for people to be able to use the app below KitKat. Once you have a transparent theme up in KitKat+ then just create an option somewhere to toggle a flag for it (a checkbox or whatever). On activity create decide what you want to be the default (transparent or not) and create two shapes or image files (one of the color of you actionbar and one black). Draw the default under your nav bar and status bar and when the user toggles the flag then just swap them out (though a restart is required to show the effect). I stored all my states in an external file that reads the values once the user loads the app and picks images based on the content of the external file. I also for good measure, made it so that my app detects the SDK version and doesn't allow users to toggle the transparent nav option if theyr'e below KitKat. Does that make sense, if not I can help further?

TL;DR: make a custom theme, two images files (black and and your color), draw them under status and navbar, swap them out when user toggles something.

Here's the effect in action with my app: https://play.google.com/store/apps/details?id=com.EmergencyDirect.SOS&hl=en
 
Last edited:
Upvote 0

Similar Threads

Top