本文介绍了如何在javaFX FXML中使用CSS设置SVG的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将SVG用于按钮中的图像.但是我无法通过CSS为其填充颜色.下面是呈现按钮的代码.

I'm using SVG for an image in a button. But I'm not able to fill in color for it through CSS.Below is the code to render a button.

<Button  onAction="#closeApplication" >
<graphic>
 <SVGPath content="M10,16 10,0 0,8z" styleClass="button‐icon‐shape" />
</graphic>
</Button>

这是CSS

.button-icon-shape SVGPath{
   -fx-fill:  red;
}

推荐答案

这是它的工作方式.我必须为按钮设置样式,并使用该类为按钮中的svg设置样式.

here is how it worked.I had to style the button and use the class to style the svg in the button.

<Button  onAction="#closeApplication" styleClass="closeButton">
        <graphic>
            <SVGPath content="M10,16 10,0 0,8z"  />
        </graphic>
</Button>

这是CSS

.closeButton{

}
.closeButton SVGPath{
   -fx-fill:  red;
}

这篇关于如何在javaFX FXML中使用CSS设置SVG的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 12:43
查看更多