java - 如何动态加载 GWT 主题

标签 java gwt internationalization

我有一个基于 GWT 构建的国际化应用程序。我想动态加载GWT主题。例如:If ( localhost:8080/GWTApps/app.html ) then load this <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);
}

关于java - 如何动态加载 GWT 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33669063/

相关文章:

java - 为什么大多数示例都使用 ArrayList

java - 我可以使用 FileChannel 从不同的线程独立地寻找文件吗?

java - 使用 jfilechooser 的问题

javascript - 在基于 iframe 的文本编辑器中禁用 Firefox 和 Chrome 拼写检查

javascript - 像 jQuery 插件一样使用 GWT 小部件?

asp.net-mvc-3 - ASP.net MVC3 多语言路由重写

java - 使用 Java future 进行无限操作是错误的吗?

java - GWT:导入后 "No source code is available for type"

internationalization - 如何将国际化对象传递给 Flutter 中的子控件

c++ - C++ 中的 Unicode 不在 Mac 终端中显示