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)
- Right-click on
res
โ New โ Vector Asset. - Choose โLocal file (SVG)โ and upload your custom icon.
- Android Studio generates it inside
res/drawable/
.- Example:
ic_custom_icon.xml
.
- Example:
๐น Option B: Manually Add PNG/WebP
- Copy your icon image.
- Paste it inside
res/drawable/
(orres/mipmap/
for app launcher icons).- Example:
res/drawable/ic_custom.png
.
- Example:
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
- Right-click
app โ New โ Image Asset
. - Choose your custom image (PNG/SVG).
- Android Studio places it in
mipmap/
folders. - This replaces the default app icon.