2015-11-12 3 views
0

У меня есть приложение, построенное на GWT с интернационализацией. Я хочу загрузить тему GWT динамически. Например: If (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'/>. Как достичь этой динамической идеи или мысли об этом?Как загрузить тему GWT Динамически

ответ

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

Спасибо за предложение (+1) –

Смежные вопросы