A Kotlin Multiplatform library to generate compose.ui.graphics.vector.ImageVector
from .xml
files.
Visit the project website for documentation.
Create a folder called xml-images
in the module folder.
:module/xml-images
![Captura de pantalla 2024-01-05 a las 16 57 56](https://private-user-images.githubusercontent.com/26246782/294544972-97c4082a-28d8-4009-addd-427d9f893340.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyODE4OTksIm5iZiI6MTcyNDI4MTU5OSwicGF0aCI6Ii8yNjI0Njc4Mi8yOTQ1NDQ5NzItOTdjNDA4MmEtMjhkOC00MDA5LWFkZGQtNDI3ZDlmODkzMzQwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIxVDIzMDYzOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTIzOWUzOGQ0MDg5OTA0NjlkZmRjMjU5YjEzNmM1Y2VkYWFjYTM3MDk0YWY1YzQ5ODY3NjBlMmE3Mjk4Y2Y1NTQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.jvfaMSqY0WohomiRkkHVxxY40jYjBx_4UihRF2gO7J0)
![Captura de pantalla 2024-01-05 a las 17 10 28](https://private-user-images.githubusercontent.com/26246782/294547755-2c0a380d-2580-4898-b581-560e4b7c6e6b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyODE4OTksIm5iZiI6MTcyNDI4MTU5OSwicGF0aCI6Ii8yNjI0Njc4Mi8yOTQ1NDc3NTUtMmMwYTM4MGQtMjU4MC00ODk4LWI1ODEtNTYwZTRiN2M2ZTZiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIxVDIzMDYzOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTlmMDRhMTk1N2M0ODVlOWE5OTcyNzdmM2I2NGQzOGQ1ZTkyMDZhMGFiZmI4ZGE4M2Q2ZjMwOGYxN2NjY2JlMTMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.jiWxtyMhzuavlz-W39OlMIGYKDAQFHB2CbV6sqeJzts)
You can manually generate ImageVector for these XML files by calling gradle generateImages
. This will create a Kotlin file for each XML file containing the ImageVector in the build folder.
![Captura de pantalla 2024-01-05 a las 17 00 45](https://private-user-images.githubusercontent.com/26246782/294545650-45ed3cd3-5773-4cf7-9474-4ef6a30a6476.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyODE4OTksIm5iZiI6MTcyNDI4MTU5OSwicGF0aCI6Ii8yNjI0Njc4Mi8yOTQ1NDU2NTAtNDVlZDNjZDMtNTc3My00Y2Y3LTk0NzQtNGVmNmEzMGE2NDc2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIxVDIzMDYzOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJiM2U3ZjY3NTJlYzhiMzMyMDk1MDBiYmQ5OWZjNzEwZDI4MWI0Y2Y1M2NiNmY4ZjQ1ZjMwYzJiOGQxYWVkN2QmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.mKeqokPRBXRt-_KYlmdl881qnTysMfew6hmIFL1azHE)
Now, you can use reference this image in the Compose code:
Icon(Images.Icons.Add, contentDescription = null)
Note that automatically a category called "Icons" has been created. A category is created for each subfolder in xml-images
folder.
It also supports theme attributes. If you are using theme color attributes, like ?attr/colorPrimary
or ?attr/colorSecondary
, they can be converted to Compose MaterialTheme
tokens, which means that
you can update illustration colors based on the token values. It is also compatible with Material3 dynamic colors.
It also supports theme attributes. If you are using theme color attributes, like ?attr/colorPrimary
or ?attr/colorSecondary
, they can be converted to Compose MaterialTheme
tokens, which means that
you can update illustration colors based on the token values. It is also compatible with Material3 dynamic colors.
<path
android:pathData="..."
android:fillColor="?attr/colorPrimary"/>
Note
It requires use Compose Material 3 dependency.
Copyright 2024 Sergio Belda
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.