通过代码更改 Vaadin 7 中的主题 [英] Change themes in Vaadin 7 via code
问题描述
我正在 Vaadin 7 中做一个项目.我需要更改页面的主题.
I am doing a project in Vaadin 7. In that I need to change the theme of a page.
在 Vaadin 6 中,有一个名为setTheme()"的函数.这样我就可以在代码中的任何地方使用该函数更改主题.
In Vaadin 6, there is a function called 'setTheme()'. so that I can change the theme using that function wherever I want in my code.
但是,在 Vaadin 7 中,我找不到类似的东西.
But, In Vaadin 7, I couldn't find any like that.
我知道会有办法做到这一点.
I know there will be a way to do it.
以及如何在更改主题时在 UI 上应用更改?
And also how to apply changes on the UI when I change a theme?
会自动更改吗?(或)
ICEPush 会帮助我吗?
ICEPush gonna help me?
推荐答案
因为我使用了自定义主题,所以我把它变得非常简单.我每次都使用切换按钮并执行所需的代码段.
Since I used custom themes, I have made it pretty simple. I used a toggle button and executed the required piece of code every time.
JavaScript.getCurrent().execute("document.body.className = document.body.className.replace(\"theme1\",\"theme2\"); ");
JavaScript.getCurrent().execute("document.body.className = document.body.className.replace(\"theme2\",\"theme1\"); ");
我的 css 文件会是这样.
My css file will be like this.
.theme1 .v-button {
/* some css attribute */
}
.theme2 .v-button {
/* some css attribute */
}
相信我;主题切换速度非常快,因为浏览器本身会切换主题,而不是要求 Vaadin 服务器进行切换.
Believe me; the theme switch is very very fast since the browser itself do the trick to switch the theme rather than asking the Vaadin server to do the switch.
这篇关于通过代码更改 Vaadin 7 中的主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!