ActionBar
Text Color
Android Development
UI Design
Mobile App Development

ActionBar text color

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Changing ActionBar text color on Android is mostly a theming problem, not a runtime widget problem. The right approach depends on whether you are using the legacy ActionBar API or the modern Toolbar through AppCompat. In most apps, the cleanest fix is styling through themes instead of setting colors manually in every activity.

Know Which API You Are Actually Using

Older apps may use the platform ActionBar, while most modern apps use Toolbar through Theme.AppCompat or Material themes. The configuration points are similar, but not identical.

If your app uses AppCompatActivity, assume you are styling the support action bar or toolbar, not the old platform-only component.

Theme-Based Styling Is the Preferred Approach

The title text color usually comes from the action bar theme or toolbar title text appearance.

Example in themes.xml:

xml
1<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
2    <item name="colorPrimary">#1F2937</item>
3    <item name="colorPrimaryDark">#111827</item>
4    <item name="android:textColorPrimary">#FFFFFF</item>
5</style>

For AppCompat toolbars, a more explicit style is usually better:

xml
<style name="AppToolbar" parent="Widget.AppCompat.Toolbar">
    <item name="titleTextColor">#FFFFFF</item>
</style>

Then apply it:

xml
1<androidx.appcompat.widget.Toolbar
2    android:id="@+id/toolbar"
3    android:layout_width="match_parent"
4    android:layout_height="?attr/actionBarSize"
5    style="@style/AppToolbar" />

Set Up a Toolbar in Code

If you use a custom toolbar, connect it as the support action bar.

kotlin
1import android.os.Bundle
2import androidx.appcompat.app.AppCompatActivity
3import androidx.appcompat.widget.Toolbar
4
5class MainActivity : AppCompatActivity() {
6    override fun onCreate(savedInstanceState: Bundle?) {
7        super.onCreate(savedInstanceState)
8        setContentView(R.layout.activity_main)
9
10        val toolbar = findViewById<Toolbar>(R.id.toolbar)
11        setSupportActionBar(toolbar)
12        supportActionBar?.title = "Dashboard"
13    }
14}

When the toolbar style defines titleTextColor, the title will follow it automatically.

Programmatic Override for Edge Cases

Sometimes theme changes are not practical, for example in one-off branded screens. You can set the title color directly on Toolbar.

kotlin
val toolbar = findViewById<Toolbar>(R.id.toolbar)
toolbar.setTitleTextColor(0xFFFFFFFF.toInt())

This is useful for isolated screens, but it should not become the default styling strategy across the app.

Activity-Level Theme Overrides

If one screen needs a different top-bar style, apply a dedicated theme to that activity instead of branching in code everywhere.

xml
1<style name="Theme.App.Special" parent="Theme.AppCompat.Light.DarkActionBar">
2    <item name="colorPrimary">#7C2D12</item>
3    <item name="colorPrimaryDark">#431407</item>
4    <item name="android:textColorPrimary">#FFFFFF</item>
5</style>

This keeps styling centralized and easier to maintain than repeated runtime overrides.

Subtitle and Action Item Colors

Title color changes do not automatically solve every text element in the top bar. You may also need to style:

  • Subtitle text color.
  • Navigation icon tint.
  • Overflow icon tint.
  • Menu item text color in custom cases.

Example:

kotlin
toolbar.setSubtitleTextColor(0xFFCBD5E1.toInt())

If only the title changes and other elements remain unreadable, the theme is still incomplete.

Material Theme and Contrast

Top-bar text color should be chosen with contrast in mind. A light text color on a dark colorPrimary is common, but test both light and dark themes if your app supports them.

Hardcoding white text without checking background can make the title unreadable when theme colors evolve later.

Common Pitfalls

  • Styling the old ActionBar when the app actually uses Toolbar.
  • Applying one-off programmatic colors instead of fixing the theme.
  • Changing title color but forgetting subtitle, icons, or menu items.
  • Using low-contrast text that fails accessibility checks.
  • Expecting layout XML alone to override a conflicting app theme.

Summary

  • ActionBar title color is usually best controlled through theme or toolbar style.
  • In modern Android apps, think in terms of Toolbar and AppCompat styling.
  • Use programmatic color changes only for narrow, intentional overrides.
  • Style related elements such as subtitle and icons together.
  • Prioritize contrast and consistency so the title remains readable across themes.
  • Prefer theme-level fixes first, because they age better than scattered per-screen tweaks.

Course illustration
Course illustration

All Rights Reserved.