Google Material Vector Icons in KMP Compose Multiplatform

In today’s tutorial, we will learn How to integrate Google material vector icons in KMP Kotlin Compose Multiplatform for Android, iOS, and Desktop applications.

Material 3 Icons

Integrate Google Material Vector Icons in KMP Compose Multiplatform:

Google Material Icons is one of the best free icon platforms available online. You can download free vector icons from fonts.google.com/icons. Material libraries can distribute these icons more conveniently on mobile and web platforms. One of them is the “material-icons-extended” library. With the help of this library, we can easily access material icons in the Kotlin Compose multiplatform application. Now, let’s get started with the library installation and icon integration.

Add Material Icons dependency in KMP Kotlin Compose Multiplatform app.

1. Open your KMP or KMM project’s build.gradle.kts file.

KMP App level build.gradle.kts file

2. Put the material dependency below in the common main section. You can find the latest version of this dependency on Maven. Here is the link: mvnrepository.com.

3. Click on the SYNC NOW button and wait a few minutes to download and Sync the dependency in your project.

Start coding for the app:

1. After syncing the project, all the material vector icons will be accessible in your project. You can find the list of all vector icons HERE.

2. Open your project’s App.kt file and integrate code for creating your first Google material vector icon.

Code explanation:

  • imageVector: Vector icon name. There are two icon types: Outlined and Filled.
  • contentDescription: Small description of your icon.
  • tint: Icon background color.
  • modifier: To set icon width, height padding, and more. You can learn more about the Modifier properties HERE.

Output:

Favorite Icon

3. Creating a Home outlined icon. I am using the HEX color code for this icon. In this code, “0xFF00B8D4,” oxFF is a prefix, and after that, put your HEX color code.

Output:

4. Creating Home filled icon.

Output:

5. Creating Setting Filled and Outlined icons.

Output:

Settings icon

Complete source code for App.kt file:

Output in Andorid device:

Google Material Vector Icons in KMP Compose Multiplatform

Output in iOS device:

Google Material Vector Icons in KMP Compose Multiplatform

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *