How to Load GWT theme Dynamically

本小妞迷上赌 提交于 2019-12-12 02:19:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!