0

I want to customize my togglebutton so that they receive this: enter image description here but for now I can not change my style

I do not see how to add a background. When I do a tb.background = "#FF0000"

DenisMasot
  • 697
  • 5
  • 11
  • 21

1 Answers1

0

The error message tells you what to do to fix your problem:

tb.background = "#FF0000"

"Type mismatch: inferred type is String but Drawable! was expected"

Backgrounds must be of type Drawable (ignore the exclamation mark for now but it basically means that Kotlin can't infer if the Drawable has to be null or non-null).

You have passed a String as a background - hence the type mismatch.

To fix it, have a look at this question and adapt one of the answers there.

David Rawson
  • 20,912
  • 7
  • 88
  • 124
  • 2
    Mind: that's a **toggle button**, and change of backgroudColor in toggle buttons would change the background of the button, rather than the ToggleButton's on/off state colors. – Eugene Kartoyev Jul 06 '18 at 00:30
  • @EugeneKartoyev thanks I didn't see it was a ToggleButton. But I'm hoping the OP can be empowered to solve this one themselves as well – David Rawson Jul 06 '18 at 00:33
  • I generate a list of togglebutton in the block RadioGroup so I do not see how I can do without going through the kotlin – DenisMasot Jul 06 '18 at 01:16