I'm using gwt 2.3.0 in my project. I need to change my css source:
<link type="text/css" rel="stylesheet" href="gxt/css/gxt-all.css">
during run time (i want to decide which file to use on onModuleLoad method). what is the best wat to do so?
To inject a CSS file, you need to proceed in a similar way as ScriptInjector
does for javascript file :
/** Load CSS file from url */
public static void loadCss(String url){
LinkElement link = Document.get().createLinkElement();
link.setRel("stylesheet");
link.setHref(url);
nativeAttachToHead(link);
}
/**
* Attach element to head
*/
protected static native void nativeAttachToHead(JavaScriptObject scriptElement) /*-{
$doc.getElementsByTagName("head")[0].appendChild(scriptElement);
}-*/;
@jusio:
StyleInjector.inject(...)
works with CSS content only :
StyleInjector.inject(".myClass{color:red;}");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With