Reputation: 494
I am trying to load SVG file in Jetpack compose, but it turned out to be black when i run it on the phone.
Here is the image from my phone.
I don't want to use tint
modifier, because it is going to load the SVG in a single color.
Upvotes: 5
Views: 19666
Reputation: 1413
You can use painterResource with tint option to tint a vector. It will not cover whole svg in one color.
Icon(
painter = painterResource(id = R.drawable.ic_crop_square),
contentDescription = "Localized description",
modifier = Modifier
.size(AssistChipDefaults.IconSize),
tint = color,
)
Result:
Upvotes: 4
Reputation: 5235
Use Image
composable instead of Icon
. Icon is doing tint by default. Source - you can read the docs for Icon
.
Icon component that draws [imageVector] using [tint], defaulting to [LocalContentColor].
Also - you can just use painterResource
instead of ImageVector.vectorResource
.
And just for the future - never attach code as a screenshot on StackOverflow. Just attach code
Upvotes: 21