Android - How to remove the title bar from your application activity

There are three easy ways you can remove the title bar/ action bar from your Android application:

  • Setting the <style> tag parent attribute value inside res/styles.xml file
  • Hide the action bar from activity class using getSupportActionBar().hide() method

Let’s start by learning how to change the styles.xml file

Remove Android title bar from the main themes file

To remove the title bar/ action bar from your Android application, you can set the <style> tag in your application to NoActionBar.

When you create a new Android application using Android Studio, the <style> tag for your application is commonly generated at Project -> app -> src -> main -> res -> values -> styles.xml or themes.xml depending on your Android Studio version.

The content of the XML file looks similar to this:

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.NoBar" 
        parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
    </style>
</resources>

You just need to change the action bar from DarkActionBar to NoActionBar at line 4 of the code above:

<style name="Theme.NoBar" 
    parent="Theme.MaterialComponents.DayNight.NoActionBar">

Additionally, you may also have the values-night folder inside the res folder as shown below:

The values-night folder contains another theme.xml that your Android app will use when the user uses the Dark Theme.

You may also want to set the parent attribute of the <style> tag in this theme.xml to NoActionBar to make your application consistent.

Setting the <style> tag to use NoActionBar will remove the title bar from all activities inside your application.

Remove Android title bar from specific activities

When you want to remove the title bar for one particular activity, you need to hide the title bar from the activity class file.

For example, here’s how you can remove the title bar from your MainActivity class:

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide();
        setContentView(R.layout.activity_main);
    }
}

Note that getSupportActionBar() is available only when your class extends AppCompatActivity. If you’re extending Activity class, you need to call getActionBar() method instead:

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getActionBar().hide();
        setContentView(R.layout.activity_main);
    }
}

If you’re using Kotlin, then set the call to supportActionBar or actionBar as follows:

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.hide()
        setContentView(R.layout.activity_main)
    }
}

And that’s how you can remove the title bar from your Android application 😉

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.