Stephen
Stephen

Reputation: 762

Changing app theme at runtime using using external theme file

I want to produce a single app that would let the user select a theme and have this applied over the entire app.

I understand that this can be achieved by using setTheme in onCreate of each activity.

But I need this to work in a different way. I don't want to have the themes stored in theme.xml or styles.xml.

I want to have a list of themes stored on the web and be able to dynamically download a new theme and have it applied in the app. I want to be able to create new themes without having to build a new version or an updated version of the app.

Images would be easy to replace. Just download from a url and store locally to be re-used. But the actual theme of the app, the colours of buttons etc should be changed at run time from a theme.xml file which isn't part of the apk but is fetched online.

Is this possible?

Upvotes: 5

Views: 1584

Answers (1)

Ben
Ben

Reputation: 1295

It depends how much styling you want to be able to do. You currently can't set view items styles grammatically outside of using a resource. But you can control things like text color and background color. If that's all you need to change, I would recommend writing a Theme factory class for you app that you use to get each view element you need. For example a getButton() function that will return you a button with the background color and text color you need.

Upvotes: 2

Related Questions