Android Development
ActionBar Customization
Android UI
Change ActionBar Title
Modify ActionBar Icon

How do I change the android actionbar title and icon

Master System Design with Codemia

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

Introduction

In older Android apps people say “ActionBar,” but in modern apps the real answer is usually “Toolbar configured as the support action bar.” You can still change the title and icon, but the exact API depends on whether you mean the app title, the logo, or the navigation icon.

That distinction matters because many code samples mix them together. The title text, app logo, launcher icon, and back arrow are different UI elements.

Change the Title Programmatically

If your activity uses AppCompat:

kotlin
1class MainActivity : AppCompatActivity() {
2    override fun onCreate(savedInstanceState: Bundle?) {
3        super.onCreate(savedInstanceState)
4        setContentView(R.layout.activity_main)
5
6        supportActionBar?.title = "Dashboard"
7    }
8}

Java version:

java
1public class MainActivity extends AppCompatActivity {
2    @Override
3    protected void onCreate(Bundle savedInstanceState) {
4        super.onCreate(savedInstanceState);
5        setContentView(R.layout.activity_main);
6
7        if (getSupportActionBar() != null) {
8            getSupportActionBar().setTitle("Dashboard");
9        }
10    }
11}

This changes the action bar title for the current activity.

Set the Default Title in the Manifest

If you want the title to be static for an activity, set it in the manifest:

xml
<activity
    android:name=".MainActivity"
    android:label="Dashboard" />

This is a good choice when the title does not change at runtime.

Change the Logo or Icon

What many people call the “action bar icon” is often the logo area to the left of the title. To show a custom logo:

kotlin
1supportActionBar?.apply {
2    setDisplayUseLogoEnabled(true)
3    setDisplayShowHomeEnabled(true)
4    setLogo(R.drawable.ic_brand_logo)
5}

This does not change the launcher icon of the app. It changes the icon area inside the bar itself.

If you are using a Toolbar, you can also set the logo directly:

kotlin
1val toolbar = findViewById<Toolbar>(R.id.toolbar)
2setSupportActionBar(toolbar)
3toolbar.logo = ContextCompat.getDrawable(this, R.drawable.ic_brand_logo)
4toolbar.title = "Dashboard"

If what you really want is the back arrow or hamburger icon, that is the navigation icon, not the title icon or logo.

Example:

kotlin
val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)
toolbar.navigationIcon = ContextCompat.getDrawable(this, R.drawable.ic_arrow_back)

Or through the action bar:

kotlin
supportActionBar?.setDisplayHomeAsUpEnabled(true)

That enables the Up button, which is different from setting a logo.

Modern Recommendation: Use a Toolbar

In current Android apps, a Toolbar is usually more flexible than relying on the old built-in action bar.

Layout:

xml
1<androidx.appcompat.widget.Toolbar
2    android:id="@+id/toolbar"
3    android:layout_width="match_parent"
4    android:layout_height="?attr/actionBarSize"
5    android:background="?attr/colorPrimary"
6    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

Activity setup:

kotlin
1class MainActivity : AppCompatActivity() {
2    override fun onCreate(savedInstanceState: Bundle?) {
3        super.onCreate(savedInstanceState)
4        setContentView(R.layout.activity_main)
5
6        val toolbar = findViewById<Toolbar>(R.id.toolbar)
7        setSupportActionBar(toolbar)
8
9        supportActionBar?.title = "Dashboard"
10        toolbar.logo = ContextCompat.getDrawable(this, R.drawable.ic_brand_logo)
11    }
12}

This gives you more control over styling and behavior than the old legacy action bar APIs.

Know Which Icon You Mean

There are at least three different “icons” developers commonly confuse:

  • launcher icon shown on the home screen
  • logo icon shown inside the toolbar
  • navigation icon such as the back arrow

Changing one does not change the others. Many confusing Android UI bugs come from using the right API for the wrong visual element.

Common Pitfalls

One common mistake is trying to change the launcher icon by calling toolbar or action bar methods. That only affects the runtime UI bar, not the app icon in the launcher.

Another mistake is assuming setLogo() will always show the way you expect. Some themes and layouts prioritize the title or home indicator differently.

It is also easy to mix old framework ActionBar code with AppCompat Toolbar code. In a modern app, choose the AppCompat path and stay consistent.

Finally, if supportActionBar is null, the activity probably is not using an action bar theme or has not called setSupportActionBar(toolbar) yet.

Summary

  • Change the title with supportActionBar?.title or a manifest label.
  • Change the bar logo with setLogo() or toolbar.logo.
  • Change the back or menu graphic through the navigation icon APIs.
  • Prefer a Toolbar with setSupportActionBar() in modern Android apps.
  • Be clear about whether you mean title, logo, launcher icon, or navigation icon, because they are different UI elements.

Course illustration
Course illustration

All Rights Reserved.