Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

painterResource() paints my vector in Black

Okay so I have created my own .SVG vector icon and imported it as an XML in Android Studio. Now I'm trying to create an Icon using that same vector. However when I specify that vector in painterResource() it paints it in Black color. And my original SVG has multiple colors instead. Any raesons why is this happening?

Icon(
     painter = painterResource(id = R.drawable.ic_google_logo),
     contentDescription = "Google Button"
    )

When I add that icon this is what I see: enter image description here

And this is how that icon should be actually displayed: enter image description here

like image 720
Hassa Avatar asked Dec 18 '22 11:12

Hassa


2 Answers

The Icon applies a default tint (LocalContentColor.current.copy(alpha = LocalContentAlpha.current))

Use tint= Color.Unspecified to avoid it:

Icon(
     painter = painterResource(id = R.drawable.ic_google_logo),
     contentDescription = "Google Button",
     tint= Color.Unspecified
    )
like image 154
Gabriele Mariotti Avatar answered Dec 21 '22 11:12

Gabriele Mariotti


Honestly, I don't think the accepted answer is the right thing to do. Icons tint automatically to the necessary contextual color.

If you want to show an icon without tinting, I'd suggest to use an Image instead:

Image(
    painter = painterResource(id = R.drawable.ic_google_logo),
    contentDescription = "Google Button"
)
like image 43
Stefan Medack Avatar answered Dec 21 '22 11:12

Stefan Medack