Transparent background in the WebView in JavaFX

后端 未结 6 1954
后悔当初
后悔当初 2020-12-19 00:50

I need to show my webview content over parent background pattern. Is there a straightforward way to do it?

6条回答
  •  无人及你
    2020-12-19 01:43

    I'm resurrecting this because I found a better solution for the problem of having a WebView over a gradient. Suppose you have a gradient like this and want to display an HTML string over it in white color that looks something like this:

    Integer semper, est imperdiet mattis porttitor, massa vulputate ipsum

    The trick is to convert your gradient to Base64 string:

    iVBORw0KGgoAAAANSUhEUgAAAAEAAAHDCAYAAADlQnCCAAAAq0lEQVRIib2VwRWAMAhDaSdwCtd1No8uUzzp0ydBgjwvnmhCPrTKtKxbb73NXcaQLiL5j/olyhQH5JXu4H4sUGyWHAIa9VWjU9qtyAh6JGicIMJno2HcGSX3gJsCKH5EfUfHJUed+qFzekrpuVzM/oq4uFKGr/pI4B7wiP2Vgno0F/uCUQ9ZXWg4vM/JL1Hpt10Nt+hZjhCDKepxV8H3soZGWOqHP3ZSGYDdATTkg3iGU3JnAAAAAElFTkSuQmCC
    

    Since WebView loads any HTML string, this can involve that has a background. In my instance, the WebView was not occupying the whole space with the gradient, so I had to position the background as well. Following is the HTML I added to the HTML string above at the beggining:

    
    
    
    
    
    

    And at the end:

    
    

    Therefore producing such code:

    String desc = "" + description + "";
    wv_desc.getEngine().loadContent(desc);
    

    You could probably put the styles in the or load them some other way for clarity I suppose, but this is a much better work-around to anything else I found on the net for this issue.

提交回复
热议问题