Add Custom App icon in kotlin

1. Prepare Your Icon

  • Use PNG, SVG, or WebP format.
  • Recommended sizes:
    • 48ร—48 dp (for normal density)
    • Use Android Studio to generate all densities automatically.

2. Add Icon to Project

There are two common ways:

๐Ÿ”น Option A: Use Vector Asset (recommended for SVG)

  1. Right-click on res โ†’ New โ†’ Vector Asset.
  2. Choose โ€œLocal file (SVG)โ€ and upload your custom icon.
  3. Android Studio generates it inside res/drawable/.
    • Example: ic_custom_icon.xml.

๐Ÿ”น Option B: Manually Add PNG/WebP

  1. Copy your icon image.
  2. Paste it inside res/drawable/ (or res/mipmap/ for app launcher icons).
    • Example: res/drawable/ic_custom.png.

3. Use the Icon in Layout

In your XML layouts:

<Button
    android:id="@+id/btnCustom"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Click Me"
    android:drawableStart="@drawable/ic_custom"   <!-- custom icon -->
    android:padding="10dp"/>

Or for ImageView:

<ImageView
    android:id="@+id/imageIcon"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:src="@drawable/ic_custom"/>

4. Use the Icon in Kotlin Code

In your Activity/Fragment:

val button = findViewById<Button>(R.id.btnCustom)
button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_custom, 0, 0, 0)

Or set it to an ImageView:

val imageView = findViewById<ImageView>(R.id.imageIcon)
imageView.setImageResource(R.drawable.ic_custom)

5. (Optional) Use as App Launcher Icon

  1. Right-click app โ†’ New โ†’ Image Asset.
  2. Choose your custom image (PNG/SVG).
  3. Android Studio places it in mipmap/ folders.
  4. This replaces the default app icon.

Leave a Comment

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