使用外部主题文件在系统运行时更改应用主题 [英] Changing app theme at runtime using using external theme file

查看:134
本文介绍了使用外部主题文件在系统运行时更改应用主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想产生一个单一的应用程序,它可以让用户选择一个主题,有这样的应用在整个应用程序。

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

我明白,这可以通过使用的onCreate每一项活动的setTheme来实现。

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

但我需要这个以不同的方式工作。我不想有存储在theme.xml或styles.xml主题。

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.

图像很容易更换。从一个网址只要下载并存储在本地被重新使用。但应用程序的实际主题,按钮等的颜色,应在距theme.xml文件,该文件是不是APK的一部分,但在网上获取运行时改变。

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.

这可能吗?

推荐答案

这取决于你想要多少要造型能够做到。您目前不能设置视图中的项目样式进行编程使用资源的一面。但你可以控制的事情,如文本颜色和背景颜色。如果这是你需要改变,我会建议写一个主题工厂类为你的应用程序,你用它来得到你所需要的每个视图元素。例如,一个getButton函数将返回您所需要的背景颜色和文字颜色的按钮。

It depends how much styling you want to be able to do. You currently can't set view items styles programatically out side 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.

这篇关于使用外部主题文件在系统运行时更改应用主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆