In this tutorial we would learn how to remove action bar in android application. This is very basic tutorial. We already know how to remove title by using requestWindowFeature(Window.FEATURE_NO_TITLE); however, when the application starts, the action bar appears on the top side of application. For example look at below snapshot.

how to remove action bar in android application

We can use getSupportActionBar().hide(); api to hide the ActionBar.

package com.music.wiki.musikal;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.Menu;
import android.app.ActionBar;
import android.view.WindowManager;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        getSupportActionBar().hide();
        setContentView(R.layout.home_screen);
    }
}

now when we run the example code there would be no Actionbar in our application. In each activity before setting setContentView , we have to hide ActionBar by getSupportActionBar().hide();

Other Way to hide or remove ActionBar

Edit styles.xml and add  below

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
styles.xml:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
</resources>

In the above file (styles.xml ) , the name of style is AppTheme. We can use this theme by mentioning inside AndroidManifest.xml. By declaring android:theme=”@style/AppTheme” >

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.music.wiki.musikal" >
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

 




Related Contents to follow