How to add and use custom colors in an Android project

Oscar de la Hera Gomez
Four flowers that represent Kotlin, Android, Jetpack Compose and Android Studio. Beneath them sits the text "Custom Color"

A step by step guide on adding and using custom colors in a Kotlin, Jetpack Compose, Android project using Android Studio.

We recommend that you clone our Open Source Kotlin Starter Project, checking out the main branch and carrying out the steps below. The changes can be found on the tutorial/basics/custom-color branch.

git clone git@github.com:delasign/kotlin-android-starter-project.git

Please note that this tutorial covers how to add and use custom colors for both the colors.xml file as well as the Color.kt file. Each of these files use a different type of color value: ARGB Hexadecimals and android.graphics.Color.

Step One: Determine the ARGB color value

A screenshot of FixGuide's Color converter, highlighting where you can enter a hex value and where you can gather the ARGB value.

Android's color.xml file uses ARGB hexadecimals.

Use the link below to convert your color to an ARGB hexadecimal.

Make sure you copy the ARGB value.

Step Two: Add the color to the color values

A screenshot of Android Studio showing the color.xml. We have highlighted where we have added the custom color, using the code that is available below.

In res > values > color.xml, add your color using code similar to the one below.

How to use this color value

A screenshot of the ic_launcher_background.xml file in Android studio with a highlight of where we have used the custom color value.

This color can be used in your code using "@color/custom_grey", where custom_grey is the name of the color that you added.

Please note that this color type is only to be used in xml files. To use colors as part of Jetpack Compose Composables, follow the next two steps.

Step Three: Determine the Android Graphics Color

A screenshot of ConvertingColor.com showing a highlight on where you can find the Android.graphics.color.

Android's Color.kt file uses android.graphics.Color values.

Use the link below to convert your color to an android.graphics.Color.

Make sure you copy the Android value.

Step Four: Add to Colors

A screenshot of Android Studio showing the color.kt file with a highlight on the newly added value.

Under ui.theme > Colors.kt, add the android.graphics.color using code similar to the one below.

If you are using our open source project, please note that the theme folder is now found under the styleguide folder in our main branch as it forms part of the Styleguide.

val CustomGrey = Color(0xFF949494)

How to use this color value

A screenshot of Android Studio showing the Main Activity file, with a color added to the Greetings Composable.

To use this color value, provide the name to a Color parameter within a Composable.

Looking to implement light mode or dark mode?

To learn how to use dark mode or light mode, consult the tutorial below.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details