在Android中,如何随主题切换字符串值和图形资源?
对于 Android 主题,您似乎可以通过主题开关更改默认颜色和外观。但是,我也希望更改字符串值。例如,我的布局中有一个 TextView。如果我切换到蓝色主题,我希望字符串更改为“这是蓝色主题。”。我也想切换图形资源。
如何在不以编程方式生成布局或为每个品牌字符串添加 if-else 的情况下执行此操作?
谢谢!
With an Android theme, it looks like you can change the default colors and appearance with a theme switch. However, I would like string values to change as well. For example, I have a TextView in my layout. If I switch to the Blue Theme, I would like the string to change to "This is the blue theme.". I also want to switch graphic resources as well.
How can I do this without generating the layout programmatically or putting an if-else for every branded string?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了答案:我从 http:// /www.androidengineer.com/2010/06/using-themes-in-android-applications.html 我修改了它,以便 android:text 字符串引用位于样式定义内,而不是在 layout.xml 内。每当您更改主题时,该字符串都会自动更新。
I found the answer: I took the example from http://www.androidengineer.com/2010/06/using-themes-in-android-applications.html and I modified it so that the android:text string reference is inside the style definition and not inside the layout.xml. The string will then be automatically updated whenever you change themes.