如何动态加载GWT主题 [英] How to Load GWT theme Dynamically
问题描述
我有一个以GWT为基础构建的国际化应用程序。例如:If( localhost:8080 / GWTApps / app.html
)然后加载这个<继承名称='com.google.gwt.user.theme.clean.Clean'/>
主题或其他( localhost:8080 / GWTApps / app.html& local = ar
)载入这个< inherits name ='com.google.gwt.user.theme.clean.CleanRTL'/>
。如何实现这个动态地对此有何想法或想法? gwt showcase 可以在EntryPoint中执行此操作。只需添加这些方法并在启动时调用 injectThemeStyleSheet()
private native HeadElement getHeadElement()/ * - {
return $ doc.getElementsByTagName(head)[0];
} - * /;
/ **
*根据当前
*语言环境的RTL方向注入GWT主题样式表。
* /
private void injectThemeStyleSheet(){
//您可以继承gwt.xml中的任何样式并通过更改THEME字符串来更改整个主题
// String THEME =chrome或dark或standard
String THEME =clean;
//根据区域设置选择名称样式表。
String styleSheet =gwt /+ THEME +/+ THEME;
styleSheet + = LocaleInfo.getCurrentLocale()。isRTL()? _rtl.css:.css;
//载入GWT主题样式表
String modulePath = GWT.getModuleBaseURL();
LinkElement linkElem = Document.get()。createLinkElement();
linkElem.setRel(stylesheet);
linkElem.setType(text / css);
linkElem.setHref(modulePath + styleSheet);
getHeadElement()。appendChild(linkElem);
}
I have an application built on GWT with internationaliation. I want to load the GWT theme dynamically.For example:If (localhost:8080/GWTApps/app.html
) then load this <inherits name='com.google.gwt.user.theme.clean.Clean'/>
theme or else (localhost:8080/GWTApps/app.html&local=ar
) load this <inherits name='com.google.gwt.user.theme.clean.CleanRTL'/>
.How to achieve this dynamically any idea or thoughts on this?
the gwt showcase does it in the EntryPoint. just add these methods and call injectThemeStyleSheet()
at startup
private native HeadElement getHeadElement() /*-{
return $doc.getElementsByTagName("head")[0];
}-*/;
/**
* Inject the GWT theme style sheet based on the RTL direction of the current
* locale.
*/
private void injectThemeStyleSheet() {
//you could inherit any style in your gwt.xml and change the whole theme by changing the THEME string
//String THEME = "chrome" or "dark" or "standard"
String THEME = "clean";
// Choose the name style sheet based on the locale.
String styleSheet = "gwt/" + THEME + "/" + THEME;
styleSheet += LocaleInfo.getCurrentLocale().isRTL() ? "_rtl.css" : ".css";
// Load the GWT theme style sheet
String modulePath = GWT.getModuleBaseURL();
LinkElement linkElem = Document.get().createLinkElement();
linkElem.setRel("stylesheet");
linkElem.setType("text/css");
linkElem.setHref(modulePath + styleSheet);
getHeadElement().appendChild(linkElem);
}
这篇关于如何动态加载GWT主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!