开发者

In Android, how can string values and graphic resources be switched with a theme?

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 wo开发者_开发知识库uld 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜