Background color is not showing through button

72 Views Asked by At

I am trying to add a color to a button. I can tell the color is there at the corners, but the button is blocking out the color.

Here is my code--Windows 11, go version 1.20.2, fyne v2.4.2

package main

import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"fyne.io/fyne/v2/canvas"
"image/color"
)

 func main() {
a := app.New()
w := a.NewWindow("Button")

     w.Resize(fyne.NewSize(100,100))
     btn := widget.NewButton("Blue Button", nil)
     rect := container.NewMax(canvas.NewRectangle(
            color.NRGBA{R: 0, G: 0, B: 180, A: 255}), btn)
w.SetContent(rect)
w.ShowAndRun()
}

The line rect := ... is, I believe, exactly what I found Andy Williams recommended on two different sites. I expected to see a blue button. I get a very light gray button showing tiny specs of blue at to corners. What am I missing?

1

There are 1 best solutions below

2
On

That was a workaround from past versions that now only works if you set the theme button colour to transparent.

The supported way is to use the “importance” field which provides meaningful state/indication, such as “danger” and “warning”.