在Android中,如何随主题切换字符串值和图形资源?

发布于 2024-10-05 00:24:37 字数 181 浏览 1 评论 0原文

对于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别忘他 2024-10-12 00:24:37

我找到了答案:我从 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文