【问题标题】:How to Load GWT theme Dynamically如何动态加载 GWT 主题
【发布时间】:2015-11-12 10:17:09
【问题描述】:

我有一个基于 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'/>。如何动态实现此目标或想法?

【问题讨论】:

    标签: java gwt internationalization


    【解决方案1】:

    gwt showcase 在入口点执行此操作。只需添加这些方法并在启动时调用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);
    }
    

    【讨论】:

    • 感谢您的建议(+1)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-08
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多