问题
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?
回答1:
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);
}
来源:https://stackoverflow.com/questions/33669063/how-to-load-gwt-theme-dynamically