Search code examples
gwtgwtbootstrap3

GWT Bootstrap3 dynamic theme


I'm trying to dynamically change bootstrap themes with GWTBootstrap3. I'm not sure where to start looking, so I haven't tried anything at all. I found an outdated article for the older gwt-boostrap. But all I've found for bootstrap3 is this info which only shows how to attach a theme. I need to be able to switch it based on variables in the code.


Solution

  • I changed my bootstrap include in the gwt.xml to :

    <inherits name="org.gwtbootstrap3.GwtBootstrap3NoTheme"/>
    

    then I included a function I found here on stackoverflow to load the bootstrap I downloaded:

    public static native void loadCss(String url)/*-{
            var fileref=document.createElement("link");
            fileref.setAttribute("rel","stylesheet");
            fileref.setAttribute("type","text/css");
            fileref.setAttribute("href", url);
            $doc.getElementsByTagName("head")[0].appendChild(fileref);
        }-*/;
    

    This allows me to decide which theme I want to load. If you want the stock theme, you will have to manually load it as well.