0

i'm encountering an issue. I'm developping an Android application which contains several Activities. And i want to let the user choose black or white design dynamically. My issue is that i don't know how i must change the design for my Activites when they're on the backstack. I though about 2 options :

  • Change programmatically the color of each view on each activity.
  • Do two versions of each activity. A black one and a white one and switch beetween them according to the user color choice.

Which one is the better way ? Is there another way to achieve this ?

Regards.

elnono
  • 33
  • 5
  • You have to [set the theme programatically.](https://www.google.com/search?q=android+change,+application,+app,++theme+programmatically) – VenomVendor Aug 18 '14 at 08:08

1 Answers1

2

You want to use Themes, and you can apply theme before calling super.onCreate()

Display Name
  • 8,022
  • 3
  • 31
  • 66
  • Ok but the onCreate will be fired only during creation of the Activity and not when you resume it (if it was on the backstack and you go back on it pressing back button. There will be a theme already applied on the Activity and i will need to switch the theme, how can i do this ? you think onCreate will do the job ?) – elnono Aug 18 '14 at 08:15
  • Yes, that's why you will need to recreate it. @elnono – Display Name Aug 18 '14 at 08:17
  • Okay so how can i apply them ? i need to call setContentView(blackXML) if i want black design. Or setContentView(whiteXML) if i need white design ? So that means that i need to create two xml layout for each Activity, a white theme and a black theme isn't it ? – elnono Aug 18 '14 at 08:24
  • @elnono call setTheme() with your theme id, and use the same layout xml. Seems like you are not currently using themes, so go ahead and learn them. – Display Name Aug 18 '14 at 08:34