1

I have such an implemenation

Surface(
                    modifier = Modifier.background(Color.Transparent),
                    shape = RoundedCornerShape(corner = CornerSize(2.dp)),
                    border = BorderStroke(width = 1.dp, color = showpageColorAgvotBoarder)
                ) {
                    Text(
                        modifier = Modifier.padding(2.dp),
                        text = item,
                        style = ShowpageAgvotStyle
                    )
                }

the result I get is

enter image description here

Like entire background is black, however, surface backgroudn is white...

I need just a boarder and background of surface should be transparent (in this case black as entire background is black)

What am I doing wrong?

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Sirop4ik
  • 4,543
  • 2
  • 54
  • 121

3 Answers3

7

You need to use color = Color.Transparent parameter instead of Modifier.background(Color.Transparent)

Surface(
    modifier = Modifier,
    shape = RoundedCornerShape(corner = CornerSize(2.dp)),
    border = BorderStroke(width = 1.dp, color = Color.Red),
    color = Color.Transparent // This is what you're missing
) {
   Text(
        modifier = Modifier.padding(2.dp),
        text = "item",
        color = Color.Gray
   )
}
Sahal Nazar
  • 625
  • 4
  • 9
3

The background color of the Surface is based on the color attribute.
By default is:

  • MaterialTheme.colors.surface (M2)
  • MaterialTheme.colorScheme.surface (M3).

Use:

Surface(
    color = Color.Transparent,
    //..
) {
     //...
}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
1

Surface has a new color parameter that dictates the color instead of the modifier.

Richard Onslow Roper
  • 5,477
  • 2
  • 11
  • 42