我有一个基于 GWT 构建的国际化应用程序。我想动态加载GWT主题。例如:If ( localhost:8080/GWTApps/app.html
) then load this <inherits name='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];
}-*/;
/**
* 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);
}
关于java - 如何动态加载 GWT 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33669063/