5

I mean ways other than using vectorResource(id = ...) (this confuses me with constant calls to context, resources, and other things).

I ask this because i see that we can make TextStyles, Shapes, Colors and Strings without smthngResource using.

As example iconAccent = Color(context.getColor(R.color.iconAccent))

Edit 1:
I found Bitmap.asImageAsset() method, it doesn't work in my case because vectors, but may be useful for somebody.

Edit 2:
I get the result by this way:

val group = ContextCompat.getDrawable(context, R.drawable.icon_group) as VectorDrawable
DrawableCompat.setTint(group, context.getColor(R.color.foregroundMain))
group = group.toBitmap().asImageBitmap()

DrawableCompat.setTint needed to correctly paint icons with theme color (we don't need it with vectorResource(id = ...) because it correctly take colors from fillColor property)

But it's crutch and if you know any other way - please write it. Believe compose developers will take into consideration this problem.

Gohryt
  • 353
  • 1
  • 4
  • 10
  • If you have to integrate to an existing application, this is a way to go. But if you only use Compose you could use the MaterialTheme.colors. Create an Compose project and files with the name Color, Shapes, Theme, Type should be generated. In theme the material theme is defined you can access everywhere. – 2jan222 Dec 06 '20 at 14:40

1 Answers1

1

You can use this tool (Svg2Compose : https://github.com/DenisMondon/Svg2Compose) to convert a Vector Drawable into an ImageVector.
So that you will be able to call directly:

Icons.YOUR_ICON

instead of:

vectorResource(R.drawable.your_icon)
Blunderer
  • 934
  • 7
  • 15