free web tracker
Course Content
Java Programming Basics for Android
Learn the basics of Java programming for Android app development using Android Studio. This guide covers key concepts like variables, loops, and classes to help you start building your first Android apps with confidence. Perfect for beginners!
0/10
User Interaction and App Logic
Learn how to make your app respond to users! This section covers handling clicks, getting input, showing messages, switching screens, and saving simple data. A perfect start to build interactive Android apps with real logic.
0/10
Advanced Layouts and Components
Learn to build modern Android UIs using advanced layouts like RecyclerView, CardView, TabLayout, and more. This section helps beginners create beautiful, interactive, and user-friendly app interfaces step by step.
0/10
Media and Resources
Learn how to manage media and resources in Android Studio. This section covers adding audio, images, video, using drawables, custom fonts, and handling runtime permissions—essential for building rich, engaging Android applications.
0/4
Mastering Java Android Development – Beginner

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

    • Name the file: styles.xml

    • Resource type: values

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

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, or paddingSmall
    • Use themes for app-wide consistency
    • Separate dark and light modes using values-night folders
    • Reuse styles to avoid duplication

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.