In Android development, maintaining a clean, consistent, and modern look for your application is essential. One of the most effective ways to achieve this is by using Colors, Themes, and Styles in your app’s resource system. These features not only ensure visual consistency but also make it easier to manage UI changes and support features like dark mode.
1. What Are Colors in Android?
Colors in Android are defined in the colors.xml
file under the res/values
directory.
Example:

<resources> <color name="colorPrimary">#6200EE</color> <color name="colorPrimaryDark">#3700B3</color> <color name="colorAccent">#03DAC5</color> </resources>
You can reference these colors in layout XML or programmatically using:

android:background="@color/colorPrimary"
or

ContextCompat.getColor(context, R.color.colorPrimary);
2. What Are Styles in Android?
A style is a collection of attributes that specify the appearance for a view. Styles are defined in styles.xml
.
If it doesn’t exist, you can create it manually:
- Right-click on the
values
folder >New
>Values Resource File
- Right-click on the
- Name the file:
styles.xml
- Name the file:
- Resource type:
values
- Resource type:
Example:

<style name="CustomTextViewStyle"> <item name="android:textColor">#000000</item> <item name="android:textSize">16sp</item> <item name="android:fontFamily">sans-serif</item> </style>
You can apply a style to a view:

<TextView style="@style/CustomTextViewStyle" android:text="Styled Text" />
3. What Are Themes in Android?
A theme is a style applied to an entire app or activity. Themes define default values for various UI elements.
Themes are declared in themes.xml
:

<resources xmlns:tools="http://schemas.android.com/tools"> <style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryVariant">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> </resources>
Apply a theme in AndroidManifest.xml
:

<application android:theme="@style/Theme.MyApp"> </application>
4. Supporting Dark Mode
Use the values-night/colors.xml
and values-night/themes.xml
to define dark mode variations.
If it doesn’t exist, you can create it manually
Right-click on res
folder → New
→ Android Resource Directory
- Name:
values-night
- Resource type:
values
- Click OK
- Name:

Example:
<!-- res/values-night/colors.xml --> <color name="backgroundColor">#000000</color>
5. Style Inheritance
You can inherit a style or theme using the parent
attribute:
<style name="MyCustomButton" parent="Widget.MaterialComponents.Button"> <item name="android:backgroundTint">@color/colorAccent</item> </style>
6. Best Practices
- Use semantic names like
colorPrimary
,textHeading
, orpaddingSmall
- Use themes for app-wide consistency
- Separate dark and light modes using
values-night
folders - Reuse styles to avoid duplication
- Use semantic names like
Conclusion
By leveraging colors, themes, and styles in Android, developers can build scalable, modern, and visually consistent apps. Understanding how these elements work together simplifies customization, enhances maintainability, and ensures a better user experience.