How to hide action bar before activity is created, and then show it again?

android hide action bar programmatically in fragment
android fullscreen activity no action bar
hide action bar android programmatically
hide action bar android studio
android studio remove action bar for one activity
remove actionbar in activity
android hide app bar
android action bar

I need to implement splash screen in my honeycomb app. I use this code in activity's onCreate to show splash:

setContentView(R.layout.splash);
getActionBar().hide();

and this code to show main UI after sometime:

setContentView(R.layout.main);
getActionBar().show();

But before onCreate is called and splash appears, there is small amount of time when action bar shown.

How can I make action bar invisible?

I tried to apply theme to activity without action bar:

<item name="android:windowActionBar">false</item>

but in that case getActionBar() always returns null and I found no way to show it again.

Setting android:windowActionBar="false" truly disables the ActionBar but then, as you say, getActionBar(); returns null. This is solved by:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    getActionBar().hide();

    setContentView(R.layout.splash); // be sure you call this AFTER requestFeature

This creates the ActionBar and immediately hides it before it had the chance to be displayed.

But now there is another problem. After putting windowActionBar="false" in the theme, the Activity draws its normal Window Title instead of an ActionBar. If we try to avoid this by using some of the *.NoTitleBar stock themes or we try to put <item name="android:windowNoTitle">true</item> in our own theme, it won't work. The reason is that the ActionBar depends on the Window Title to display itself - that is the ActionBar is a transformed Window Title. So the trick which can help us out is to add one more thing to our Activity theme xml:

<item name="android:windowActionBar">false</item>
<item name="android:windowTitleSize">0dp</item>

This will make the Window Title with zero height, thus practically invisible .

In your case, after you are done with displaying the splash screen you can simply call

setContentView(R.layout.main);
getActionBar().show();

and you are done. The Activity will start with no ActionBar flickering, nor Window Title showing.

ADDON: If you show and hide the ActionBar multiple times maybe you have noticed that the first showing is not animated. From then on showing and hiding are animated. If you want to have animation on the first showing too you can use this:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_ACTION_BAR);

    // delaying the hiding of the ActionBar
    Handler h = new Handler();
    h.post(new Runnable() {     
        @Override
        public void run() {
            getActionBar().hide();
        }
    });

The same thing can be achieved with:

protected void onPostResume() {
    super.onPostResume();
    getActionBar().hide();

but it may need some extra logic to check if this is the first showing of the Activity.

The idea is to delay a little the hiding of the ActionBar. In a way we let the ActionBar be shown, but then hide it immediately. Thus we go beyond the first non-animated showing and next showing will be considered second, thus it will be animated.

As you may have guessed there is a chance that the ActionBar could be seen before it has been hidden by the delayed operation. This is actually the case. Most of the time nothing is seen but yet, once in a while, you can see the ActionBar flicker for a split second.

In any case this is not a pretty solution, so I welcome any suggestions.

Addition for v7 support actionbar user, the code will be:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getSupportActionBar().hide();

How to hide Action Bar? - CodixLab, Setting android:windowActionBar="false" truly disables the ActionBar but then, as you say, getActionBar(); returns null. This is solved by: public void  In this post, I will teach you now how to hide and show Action Bar. In some scenario we need to hide Action Bar to provide more space for User to work on the applications. I would recommend you to take a look at the previous posts listed below (which are prerequisites to learn current article) so that you can learn this post with much ease.

Using this simple code in your .class file to hide action bar

getSupportActionBar().hide();

How to hide action bar in Android, In this article, We will see how to hide action bar in android app. Example: If you want to use a theme called Mytheme, You have to create another theme called NoActionBar and add these two Let me show you how we can do this from our Activity class. Again in your Activity's onCreate method just add these lines. I have an action bar at the top that contains a logo. how to hide ActionBar on certain activities. Find the activity tag for which you want to hide your

If you are using ActionBarSherlock, then use Theme.Sherlock.NoActionBar Theme in your Activity

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

Hiding the Android ActionBar, ActionBar is good for UE, but sometimes we do want to hide it. Then, open the AndroidManifest.xml and apply it to the activity you want to  If you want to avail ActionBar for earlier API level then you can use Sherlock ActionBar. Using ActionBar you can hide and show any View from your activity. Android has got support for action bar.

Create two styles:

<style name="AppThemeNoBar" parent="Theme.AppCompat.Light">
     <item name="android:windowNoTitle">true</item>
</style>

<style name="AppThemeBar" parent="Theme.AppCompat.Light">
    <item name="android:windowNoTitle">false</item>
</style>

Set AppThemeNoBar as application theme and AppThemeBar to the activity where you want to show the ActionBar. Using two styles you wont see the Action bar while views are loading.

Check this link Android: hide action bar while view load

Hide the status bar, To hide: $.index.activity.actionBar.hide();. To show again: To use this method, create as many Android themes as needed, Define the the global app theme on your tiapp.xml just like before to set your app to launch without ActionBar. we're using the ActionBar in this Window // then we need to add the  The best way to do this is two make the first activity as blank activity and the content you want to put and then after some time fire another activity. By following this way you can make the first activity as your splash screen without action bar or anything.

Hi I have a simple solution by using 2 themes

  1. Splash screen theme (add it to the manifest):

    <style name="SplashTheme" parent="@android:style/Theme.Holo.NoActionBar"> <item name="android:windowBackground">@color/red</item> </style>

  2. normal theme (add it in your activity by setTheme(R.style.Theme)):

    <style name="Theme" parent="@style/Theme.Holo"> <item name="android:windowBackground">@color/blue</item> </style>

To support SDK 10:

@Override    
public void onCreate(Bundle savedInstanceState) {

    setTheme(R.style.Theme);      
    super.onCreate(savedInstanceState);

      ...........
      ...........
}

How To Show and hide ActionBar with AppCompat v.7 , Adaptive icons · Add a floating action button · Create shadows and clip views You should never show the action bar without the status bar. information it needs to render your UI before instantiating your app's main activity. the activity​), your app needs to reset them if you want to hide the bars again. Step 7: If everything was done correctly, an Android Studio icon will now show in your launcher. If not, and you have a backup, please restore to the backup and try again. If not, and you are ok with your linux data being wiped, turn off Linux (Beta) via Settings, then turn it back on and try again from Step 2.

Android make activity as Fullscreen (Removing Title Bar or Action , Now I want to make it so the ActionBar appears only in "Display" mode, not in the (How to hide action bar before activity is created, and then show it again?). Make Content Appear Behind the Navigation Bar. On Android 4.1 and higher, you can set your application's content to appear behind the navigation bar, so that the content doesn't resize as the navigation bar hides and shows. To do this, use SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION.

Better User Interfaces with the Android Action Bar, If want to make an activity to fullscreen in some cases like playing video -to-​hide-action-bar-before-activity-is-created-and-then-show-it-again. This option is needed to show the item directly in the action bar as an icon. If there's not enough room for the item in the action bar, it will appear in the action overflow. If withText is specified as well (as in the second item), the text will be displayed with the icon. The above code results in two action icons being displayed:

How to hide action bar before activity is created, and then show it again? and here it talks about adding a line to the manifest that would do it. I recommend you to take a look at How to add Action Bar in Android Applications? post which will provide you insights on adding Action Bar. In this post, I will teach you how to handle clicks on Action Bar action items. You need to create a simple Android application with Action Bar before you proceed further.

Comments
  • For Theme.AppCompat.Light ... use this How to Answer[1] [1]: stackoverflow.com/a/25365193/1364896
  • @newton_guima yes, it does work. Just remember to use supportRequestWindowFeature(Window.FEATURE_ACTION_BAR)
  • @Cleric - How do you make all this to work with setTheme? Because your answer works great if I set the theme from the Manifest, but if I do it in onCreate (in my case the theme depends on a preference for light of dark theme) the default holo action bar flashes before the one I set in my theme anyway. But maybe this is worth another complete SO question.
  • @Cleric Thanks. I resolved my issue setting android:theme="@android:style/Theme.NoTitleBar" into the Manifest and then setTheme(R.style.MyTheme) in main activity's onCreate; This ensures (in Android 4+) avoiding the flash of the default holo ActionBar before the one I defined in my theme (I arrived here looking for a way to workaround this; I actually don't need any splash-screen).
  • I call getSupportActionBar().hide(); after getWindow().requestFeature(Window.FEATURE_ACTION_BAR); and everything blows up with a NPE. Any ideas? Problem with Theme.AppCompat?
  • @loeschg: I had the same problem and found this solution: stackoverflow.com/a/20315456/3514976
  • The same applies for standard Android 3+ ActionBar (no Sherlock): <activity android:theme="@android:style/Theme.NoActionBar">.
  • Perfect solution :) Thanks.
  • I don't see how this is an answer to Ilya's question. Setting the theme to be Theme.Sherlock.NoActionBar will mean calling getActionBar() or getSupportActionBar() (to subsequently show the action bar) returns null...
  • @AlexSemeniuk When I use that line in the manifest, I get this error: error: Error: No resource found that matches the given name (at 'theme' with value '@android:style/ Theme.NoActionBar').
  • @SiKni8 Are you sure you are using API13+ library for your application?
  • Finally! Worked for me. Thanks. :)