如何设置菜单按钮和菜单项的样式 [英] How to style menu button and menu items
问题描述
我尝试在菜单按钮中更改样式。我可以更改菜单按钮样式,但不能更改其菜单项。
无论我尝试菜单按钮内的菜单项保持不变。
I tried to change styles in menu button. I could change menu button style but not its menu item. No matter what i try menu item inside menu-button remains unchanged.
.menu-button {
-fx-background-color:black;
}
.menu-button .label {
-fx-background-color:black; }
现在我怎样才能改变遗漏的颜色?
Now how can i change color that is left out??
推荐答案
MenuButton
使用菜单
内部并具有类似的API。以这种方式 MenuButton
包含 MenuItem
的列表,就像菜单
。所以我认为你需要尝试使用 .menu
, .menu-button
和 .menu-item
caspian.css中的CSS选择器。更具体地说, .menu-item
。
MenuButton
uses Menu
internally and has a similar API. In such way that MenuButton
contains MenuItem
s list just like Menu
. So I think you need to try to play with .menu
, .menu-button
and .menu-item
CSS selectors in caspian.css. More specifically with .menu-item
.
编辑:看来你需要更改 .context-menu
,因为menuButton的弹出菜单是ContextMenu。
It seems you need to change the .context-menu
too, because the popped up menu of the menuButton is ContextMenu.
.menu-item .label {
-fx-text-fill: white;
}
.menu-item:focused {
-fx-background-color: darkgray;
}
.menu-item:focused .label {
-fx-text-fill: blue;
}
.context-menu {
-fx-skin: "com.sun.javafx.scene.control.skin.ContextMenuSkin";
-fx-background-color: black;
-fx-background-insets: 0, 1, 2;
-fx-background-radius: 0 6 6 6, 0 5 5 5, 0 4 4 4;
/* -fx-padding: 0.666667em 0.083333em 0.666667em 0.083333em; 8 1 8 1 */
-fx-padding: 0.333333em 0.083333em 0.666667em 0.083333em; /* 4 1 8 1 */
}
这篇关于如何设置菜单按钮和菜单项的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!