You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从Eclipse产品外观偏好页获取主题偏好值?

获取Eclipse UI主题偏好值的正确方法

你之前的代码返回空字符串,是因为主题偏好并不存储在org.eclipse.ui.preferencePages.Views节点下。Eclipse的主题设置实际保存在org.eclipse.e4.ui.css.swt.theme偏好节点中,对应的键为themeid。

正确的代码实现如下:

import org.eclipse.core.runtime.Platform;

// 获取当前激活的主题ID
String activeThemeId = Platform.getPreferencesService().getString(
    "org.eclipse.e4.ui.css.swt.theme",
    "themeid",
    "org.eclipse.ui.theme.default", // 未找到时返回的默认主题ID
    null
);

额外说明:

  • 常见主题ID示例:
    • 默认亮白主题:org.eclipse.ui.theme.default
    • 深色主题:org.eclipse.ui.theme.dark
  • 若在Eclipse启动早期获取该值,建议将代码放在IStartup实现类中,或绑定到org.eclipse.ui.startup扩展点,确保偏好服务已完成初始化,避免因时机过早导致获取失败。

内容的提问来源于stack exchange,提问作者mahesh bhagirath

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 06:01:05