How To Remove The ActionBar From Specific Activities (Android Studio)

ActionBar is a special and important part of the android app. It is a menu bar that runs across the top of the activity screen in android. Most beginners don't have enough idea about it.

removed actionbar

You will see an actionbar in every activity when you create an app for the first time. In some activities, we don't need that. In this article, I am going to show you that how you can remove the actionbar from specific activities and also from all activities.

Remove the ActionBar From Specific Activities

Suppose you are creating an app where you have a splash screen. In that case, we don't need an actionbar in that splash screen activity. Then you need to remove that actionbar from that specific activity. Here is the step-by-step process to do that.

Step 1: Go to the AndroidManifest.xml file

You can find that by double pressing on the shift key. You can see the file search option in the android studio when you double press on the shift key. Type the file name in the search field and it will show you those files.

Step 2: Find the application tag and activity tag

In the AndroidManifest.xml file, you can see the application tag. Inside the application tag, you can find the activity tag. AndroidManifest.xml file can contain multiple activity tags. It depends on how many activities the developer created during the development process.

Step 3: Find an activity tag for a specific activity

Suppose you have an activity for the splash screen and you want to remove the actionbar for that activity. Check the android:name attributes for each activity tag. If your activity name is MainActivity then the attribute value should be ".MainActivity".

Step 4: Change the theme of the activity

There ate some default themes in Android. You can apply those themes to different activities. In this case, we are going to use "Theme.AppCompat.Light.NoActionBar". This theme is going to remove the actionbar from that activity.

Here is the code that comes default:

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Here is the after adding theme:

<activity android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Here we just added the theme which helps us to make a specific activity actionbar free. Now you can apply this theme to any activity where you don't want the actionbar. Here is the line of code you have to use in the opening activity tag of an activity.

android:theme="@style/Theme.AppCompat.Light.NoActionBar"

ActionBar code android studio

Remove the ActionBar From All Activities

Most professional app developers don't like to use the default ActionBar. The recommendation is to use a toolbar instead of ActionBar. The toolbar is easier to use, fully customizable, can be used for all devices. To remove ActionBar from all activities we have to follow the steps below.

Step 1: Go to styles.xml

Using the double press on shift key method you can find out the styles.xml file. You can manually find this option in the android studio toolbar. Click on the search icon (Search Everywhere) and then type the file name in the search box.

Step 2: Change the AppTheme

If you open the styles.xml file you can see some tags. Find the style tag. The default value of the parent attribute is the dark theme. You have to change that to make all activity ActionBar free. Here is the code for no actionbar:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

Replace this line with the default theme code. Now your app has no actionbar in it. This is so much important for us to understand the basics of the actionbar. Practice it and try to implement this on different projects.

Read more: How To Change App Name In Android Studio

Post a Comment (0)
Previous Post Next Post