如何动态加载GWT主题

时间:2015-11-12 10:17:10

标签: java gwt internationalization

我有一个基于GWT的国际化应用程序。我想动态加载GWT主题。例如:如果(localhost:8080/GWTApps/app.html)然后加载此<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'/>。如何实现此目的动态的任何想法或想法吗?

1 个答案:

答案 0 :(得分:2)

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);
}