Android: how to hide ActionBar on certain activities

JavaAndroidAndroid Actionbar

Java Problem Overview


I've developed a simple demo application with a splash screen a map and some regular screens.

I have an action bar at the top that contains a logo. It all looks fine on my phone (Galaxy s1 I9000 V2.3) but when i test it on Galaxy s2 v4 the action bar appears also in the splash screen and in the map screen.

The spalsh and map activity are not even inheriting from ActionBarActivity so how is that possible and how can i make it go away?

Manifest:

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/Theme.AppCompat.Light" >
        <activity
            android:name=".HomeActivity"
            android:icon="@drawable/android_logo"
            android:label=""
            android:logo="@drawable/android_logo" >

            <!--
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            -->
        </activity>
        <activity
            android:name=".MapActivity"
            android:label="" >
        </activity>
        <activity
            android:name=".PackageActivity"
            android:icon="@drawable/android_logo"
            android:label=""
            android:logo="@drawable/android_logo" >
        </activity>
        <activity
            android:name=".SplashActivity"
            android:label="" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

    </application>

MapActivity definition (it's a long one so i included just the definition):

public class MapActivity extends FragmentActivity implements LocationListener

Splash Activity:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;

public class SplashActivity extends Activity{

	private static final long SPLASH_DISPLAY_LENGTH = 2000;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
		
        new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
                Intent mainIntent = new Intent(SplashActivity.this,HomeActivity.class);
                SplashActivity.this.startActivity(mainIntent);
                SplashActivity.this.finish();
            }
        }, SPLASH_DISPLAY_LENGTH);

	}

}

Java Solutions


Solution 1 - Java

As you are asking about how to hide in a certain activity, this is what you need :

getSupportActionBar().hide(); 

Solution 2 - Java

Apply the following in your Theme for the Activity in AndroidManifest.xml:

<activity android:name=".Activity"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Solution 3 - Java

1.Go to your manifest.xml file.

2.Find the activity tag for which you want to hide your ActionBar and then add ,

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

           <activity
            android:name=".MainActivity"
            android:theme="@style/Theme.AppCompat.NoActionBar"
            >

Solution 4 - Java

If you want to get full screen without actionBar and Title.

Add it in style.xml

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
      <item name="windowActionBar">false</item>
      <item name="windowNoTitle">true</item>
      <item name="android:windowFullscreen">true</item>
</style>

and use the style at activity of manifest.xml.

<activity ....
      android:theme="@style/AppTheme.NoActionBar" > ......
</activity> 

Solution 5 - Java

The ActionBar usually exists along Fragments so from the Activity you can hide it

getActionBar().hide();
getActionBar().show();

and from the Fragment you can do it

getActivity().getActionBar().hide();
getActivity().getActionBar().show();

Solution 6 - Java

This works for me! Put this in your Activity in manifests

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

You can also make your custom theme in styles.xml like this:

<style name="Theme.MyCustomTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name = "android:windowActionBar">false</item>
        <item name = "android:windowNoTitle">true</item>
        // more custom...
    </style>

Hope this help.

Solution 7 - Java

If you were using Theme.AppCompat.Light, a better equivalent would be Theme.AppCompat.Light.NoActionBar.

I found that using Theme.AppCompat.NoTitleBar caused my button text to be invisible so I am using Theme.AppCompat.Light.NoActionBar.

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

Solution 8 - Java

To hide the ActionBar add this code into java file.

    ActionBar actionBar = getSupportActionBar();
    actionBar.hide();

Solution 9 - Java

You can use Low Profile mode See here

Just search for SYSTEM_UI_FLAG_LOW_PROFILE that also dims the navigation buttons if they are present of screen.

Solution 10 - Java

Apply the following in your Theme for the Activity in AndroidManifest.xml:

<activity android:name=".DashboardActivity"
        android:theme="@style/AppFullScreenTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Then Apply the following in your Style in style.xml

<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

Solution 11 - Java

The above answers would help with the ActionBar thing. To add to it, use the following code in case you are using the Splash Screen: Use this before you set the content view:

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

Just to clarify, here's how you do it:

    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);         
    setContentView(R.layout.activity_main);

This would make your screen a full screen, i.e remove the top bar where you see the network bar, etc

Solution 12 - Java

@Override
    public void onResume() {
        super.onResume();
        getSupportActionBar().hide();
    }

    @Override
    public void onStop() {
        super.onStop();
        getSupportActionBar().show();
    }

Solution 13 - Java

This works in API 27

In the styles.xml replace code to the following....

<resources>
    <!-- No Action Bar -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>

Then in the files (eg. activity_list.xml) in which you do want to have a toolbar put the following code.

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/colorPrimary"/>

If you have problems switch to linear layout (because that is what this code is tested on)

Solution 14 - Java

From here:

> Beginning with Android 3.0 (API level 11), all activities that use the default theme have an ActionBar as an app bar. However, app bar features have gradually been added to the native ActionBar over various Android releases. As a result, the native ActionBar behaves differently depending on what version of the Android system a device may be using. By contrast, the most recent features are added to the support library's version of Toolbar, and they are available on any device that can use the support library.

So one option is to disable ActionBar completely (in the app manifest.xml file) and then add Toolbar in every page that needs an ActionBar.

(follow the above link for step-by-step explanation)

Solution 15 - Java

For selectively hiding Actionbar in activities:

Add the following code to onCreate (preferably on the last line of the function)

Kotlin:

supportActionBar?.hide()

Java:

getSupportActionBar().hide();

Solution 16 - Java

If you activity extends AppCompatActivity then you can add this line super.getSupportActionBar().hide(); before setContentView()

Solution 17 - Java

Replace AndroidManifest.xml

android:theme="@style/FullscreenTheme"

to

android:theme="@style/Theme.Design.NoActionBar"

Solution 18 - Java

Add New Style in your style.xml

<!-- 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>
</style>

<style name="LoginTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

and then add following line in your manifest

<activity android:name=".Login"
        android:label="@string/app_name"
        android:theme="@style/LoginTheme"
        >

Solution 19 - Java

Check for padding attribute if the issue still exists after changing theme.

Padding Issue creating a white space on top of fragment window / app window

Padding Issue creating a white space on top of fragment window / app window

Once you remove the padding - top value automatically the white space is removed.

Solution 20 - Java

First cheek MainActivity for activity tag,Like -

> public class MainActivity extends AppCompatActivity

Then goto menifest xml file and write-

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

in activity tag

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTomerView Question on Stackoverflow
Solution 1 - JavaerluxmanView Answer on Stackoverflow
Solution 2 - JavaSi8View Answer on Stackoverflow
Solution 3 - JavaPrateek JoshiView Answer on Stackoverflow
Solution 4 - Javareza.cse08View Answer on Stackoverflow
Solution 5 - JavasandaloneView Answer on Stackoverflow
Solution 6 - JavaKyo HuuView Answer on Stackoverflow
Solution 7 - JavajoshgoldeneagleView Answer on Stackoverflow
Solution 8 - JavaAJAY KACHHIYAPATELView Answer on Stackoverflow
Solution 9 - JavaTMHView Answer on Stackoverflow
Solution 10 - JavaKanaiyalal BadalView Answer on Stackoverflow
Solution 11 - JavaBlueLeafView Answer on Stackoverflow
Solution 12 - JavaAbdulkerim YıldırımView Answer on Stackoverflow
Solution 13 - JavaDragonFireView Answer on Stackoverflow
Solution 14 - JavaLoMaPhView Answer on Stackoverflow
Solution 15 - Javaan0nym0useView Answer on Stackoverflow
Solution 16 - JavananaboisonView Answer on Stackoverflow
Solution 17 - JavaTarik BillaView Answer on Stackoverflow
Solution 18 - JavaSuraj GuptaView Answer on Stackoverflow
Solution 19 - JavaAravindhan KumarView Answer on Stackoverflow
Solution 20 - JavaMonirul Islam PrinceView Answer on Stackoverflow