[英]How to change theme in SWT application
我是开发SWT应用程序的新手,并且正在寻找一种简便的方法来更改已经开发的小型应用程序的主题。
进行了一些谷歌搜索之后,我可以断定似乎存在一种称为演示文稿的东西,这似乎是我可以下载一个现成的主题并将其应用于我的应用程序的一种方式。 那正确吗?
或者,有人可以指出正确的方法来指导我吗?
谢谢
如果您只是在谈论没有Ecipse RCP的SWT,那么就无法对应用程序进行主题化。
SWT的主要优点之一是它使用OS资源来类似于系统应用程序。 使用主题会与这种方法相矛盾。
但是,如果您使用的是Eclipse RCP 4,请查看@Ran的答案。
org.eclipse.e4.ui.css.swt.theme
扩展点支持创建主题扩展。 此扩展名定义样式的ID和指向CSS文件的指针。
您还可以通过org.eclipse.core.runtime.products扩展中的cssTheme属性定义默认主题。 这也可以用于定义固定样式。
要切换样式,请使用IThemeEngine
。
package com.example.e4.rcp.todo.handlers;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.css.swt.theme.IThemeEngine;
public class ThemeSwitchHandler {
// Remember the state
static boolean defaulttheme= true;
@Execute
public void switchTheme(IThemeEngine engine) {
System.out.println("ThemeSwitchHandler called");
// The last argument controls
// whether the change should be persisted and
// restored on restart
if (!defaulttheme) {
engine.setTheme("com.vogella.e4.todo.defaulttheme", true);
} else {
engine.setTheme("com.vogella.e4.todo.redtheme", true);
}
defaulttheme= !defaulttheme;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.