有没有办法在运行时更改 android 主题?
我现在正在致力于在运行时更改android主题样式,当用户选择主题资源时,不仅当前应用程序,而且手机上安装的所有应用程序都应该更改。例如,就像您在设置活动中更改系统语言一样,所有应用程序的语言都会更改。我只是不明白 Android 框架是如何实现这一点的,有人知道吗?
当我尝试使用 PackageManager 时,就像这样:
PackageManager manager = getPackageManager();
List<ApplicationInfo> apps = manager
.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo app : apps) {
app.theme=android.R.style.Theme_Light_NoTitleBar_Fullscreen;
}
它不起作用。 ApplicationInfo 中的属性“主题”是只读的吗?
I am now working on changing android theme style at runtime, when the user select a theme resource, not only the current application, but also all the applications installed on the phone should be changed. For example, just like you change the system language in setting activity,then all the applications' language changed. I just can not figure out how Android framework achieves this, anybody know anything about this?
While I tried to use PackageManager, just like this:
PackageManager manager = getPackageManager();
List<ApplicationInfo> apps = manager
.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo app : apps) {
app.theme=android.R.style.Theme_Light_NoTitleBar_Fullscreen;
}
It won't work. Is the attribure "theme" in ApplicationInfo read-only?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为修补外国应用程序的数据不是一个好主意。您不会获得派生主题,必须检测新安装的应用程序等。
无论如何,您可能需要一部已 root 的手机才能进行此类更改,那么为什么不覆盖像 Metamorph 这样的默认主题资源以及所有这些自定义 ROM 呢?
当然,最好的解决方案是 Android 首先支持可自定义的默认主题。
I don't think it's a good idea to patch data of foreign apps. You wouldn't get derivated themes, newly installed apps must be detected, etc.
You probably would need a rooted phone for such changes anyway, so why not overwrite the default theme resources like Metamorph and all those custom ROMs do it?
Of course, best solution would be if Android would support customizable default themes in the first place.