如何动态加载 GWT 主题
How to Load GWT theme Dynamically
我有一个基于 GWT 的国际化应用程序。我想加载 GWT 主题 dynamically.For example: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 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);
}
我有一个基于 GWT 的国际化应用程序。我想加载 GWT 主题 dynamically.For example: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 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);
}