A Kotlin library for accessing Salesforce Lightning Design System (SLDS) icons in Android applications.
SLDSIcons is a pre-compiled binary library (AAR) that provides type-safe Kotlin APIs and Jetpack Compose composables for loading and rendering SLDS icons sourced from the @salesforce-ux/icons npm package. Icons are bundled inside the library as Vector Drawables, preserving vector quality at any size. Developers interact with icons through code APIs — not by accessing raw image files directly.
- Type-Safe API: Kotlin enums provide compile-time safety for icon access
- Jetpack Compose Support: Easy-to-use composables for modern Android UI
- Dynamic Categories: All icon categories from the npm package are automatically discovered and included
- Vector Drawables: Icons maintain crisp quality at any size
- Flexible Rendering: Support for custom sizing and tinting
Add SLDSIcons to your build.gradle.kts:
dependencies {
implementation("com.salesforce.android.sldsicons:slds-icons:1.0.0")
}Or in Groovy build.gradle:
dependencies {
implementation 'com.salesforce.android.sldsicons:slds-icons:1.0.0'
}Add SLDSIcons to your pom.xml:
<dependency>
<groupId>com.salesforce.android.sldsicons</groupId>
<artifactId>slds-icons</artifactId>
<version>1.0.0</version>
</dependency>SLDSIcons provides type-safe enums for accessing icons from different categories:
import com.salesforce.android.sldsicons.UtilityIcons
import com.salesforce.android.sldsicons.StandardIcons
import com.salesforce.android.sldsicons.ActionIcons
import com.salesforce.android.sldsicons.CustomIcons
// Using UtilityIcons
val addIcon = UtilityIcons.Add.getDrawable(context, size = 48)
// Using StandardIcons
val accountIcon = StandardIcons.Account.getDrawable(context, size = 64)
// Using ActionIcons
val mapIcon = ActionIcons.Map.getDrawable(context, size = 40)
// Using CustomIcons
val customIcon = CustomIcons.Custom1.getDrawable(context, size = 48)
// With custom color
val coloredIcon = UtilityIcons.Close.getDrawable(
context = context,
size = 32,
color = Color.RED
)Each icon enum provides these methods:
sealed interface SLDSIcon {
val resourceName: String
// Get the vector drawable (original colors)
fun getVectorDrawable(context: Context): Drawable?
// Get as Bitmap with default color
fun getBitmap(context: Context, size: Int): Bitmap
// Get as Bitmap with custom color
fun getBitmap(context: Context, size: Int, @ColorInt color: Int): Bitmap
// Get as Drawable with default color
fun getDrawable(context: Context, size: Int): Drawable
// Get as Drawable with custom color
fun getDrawable(context: Context, size: Int, @ColorInt color: Int): Drawable
}Use icons in Compose with the provided composable:
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.core.graphics.drawable.toBitmap
import com.salesforce.android.sldsicons.SLDSIcon
import com.salesforce.android.sldsicons.UtilityIcons
import com.salesforce.android.sldsicons.StandardIcons
@Composable
fun SLDSIcon(
icon: SLDSIcon,
size: Dp,
modifier: Modifier = Modifier,
color: Color? = null,
contentDescription: String? = null
) {
val drawable = icon.getDrawable(LocalContext.current, size.value.toInt())
Image(
bitmap = drawable.toBitmap().asImageBitmap(),
contentDescription = contentDescription,
colorFilter = color?.let { ColorFilter.tint(it) },
modifier = modifier.size(size)
)
}
// Usage examples:
@Composable
fun IconExamples() {
// Utility icon
SLDSIcon(icon = UtilityIcons.Add, size = 24.dp)
// Standard icon with custom color
SLDSIcon(
icon = StandardIcons.Account,
size = 32.dp,
color = Color(0xFF0070D2)
)
// Action icon with content description
SLDSIcon(
icon = ActionIcons.Map,
size = 40.dp,
color = Color.White,
contentDescription = "Map"
)
}Icons can also be used in traditional Android Views:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/slds_utility_add"
android:contentDescription="@string/add_icon" />| Category | Enum Class | Description | Example Usage |
|---|---|---|---|
action |
ActionIcons |
Interactive elements like buttons and controls | ActionIcons.AddContact |
standard |
StandardIcons |
Object and entity representations | StandardIcons.Account |
utility |
UtilityIcons |
General-purpose functional icons | UtilityIcons.Add |
custom |
CustomIcons |
Salesforce-specific branded icons | CustomIcons.Custom1 |
Icon enum names follow PascalCase convention:
Examples:
UtilityIcons.Add- Add icon from utility categoryStandardIcons.Account- Account icon from standard categoryActionIcons.AddContact- Add Contact icon from action categoryActionIcons.NewTask- New Task icon from action categoryCustomIcons.Custom1- Custom icon 1
Icons support custom colors and tinting:
// Default color
val icon = UtilityIcons.Add.getDrawable(context, size = 48)
// Custom color
val redIcon = UtilityIcons.Close.getDrawable(
context = context,
size = 48,
color = 0xFFFF0000.toInt() // Red
)
// In Compose with Color
SLDSIcon(
icon = UtilityIcons.Delete,
size = 32.dp,
color = Color.Red
)All icons from the @salesforce-ux/icons npm package are included in this library.
To find available icon names:
- Visit @salesforce-ux/icons on npm
- Browse the package contents to see all available icons
- Icons are organized in folders by category (
action/,standard/,utility/,custom/,doctype/) - Convert icon names to PascalCase for the enum (e.g.,
add_contact→AddContact)
Icons can be used as follows:
Action Icons:
ActionIcons.AddContact- Add contact actionActionIcons.Approval- Approval actionActionIcons.NewTask- New task actionActionIcons.Email- Email action
Standard Icons:
StandardIcons.Account- Account objectStandardIcons.Contact- Contact objectStandardIcons.Opportunity- Opportunity objectStandardIcons.Case- Case object
Utility Icons:
UtilityIcons.Add- Add iconUtilityIcons.Close- Close iconUtilityIcons.Search- Search iconUtilityIcons.Settings- Settings iconUtilityIcons.Delete- Delete icon
Custom Icons:
CustomIcons.Custom1throughCustomIcons.Custom113
- Android API 30+
- Kotlin 1.9+
- Jetpack Compose (optional, for Compose support)
- Ensure the library was properly added to your dependencies
- Verify you're using the correct API:
- Use enum-based access:
UtilityIcons.Add.getDrawable(context, size) - Don't access resources directly:
R.drawable.slds_utility_add❌
- Use enum-based access:
- Make sure you're importing the correct package:
import com.salesforce.android.sldsicons.* - Clean and rebuild your project:
./gradlew clean build
Vector drawables preserve quality at any size. If icons appear distorted:
- Use appropriate size for your use case (24dp-48dp is typical)
- Set proper ImageView scaleType:
<ImageView android:scaleType="fitCenter" android:adjustViewBounds="true" />
If you get Resources.NotFoundException at runtime:
- Ensure the library is included in your dependencies
- Check R8/ProGuard rules aren't stripping resources:
-keep class com.salesforce.android.sldsicons.** { *; } -keepclassmembers class * implements com.salesforce.android.sldsicons.SLDSIcon { public *; }
We welcome contributions! Please see CONTRIBUTING.md for details on how to get started.
Please follow our Code of Conduct.
SLDSIcons is available under the terms specified in the TERMS_OF_USE.txt file.
- SLDS Icons Reference — Browse the full list of available icons
@salesforce-ux/iconsnpm package — Source icon package