Advertisement
Advertisement


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


Question

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.

2018/06/01
1
244
6/1/2018 3:45:48 PM


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

getSupportActionBar().hide();
2015/06/15

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>
2013/02/06

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

2014/01/26

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);

      ...........
      ...........
}
2013/06/29

I was also trying to hide Action Bar on Android 2.2, but none of these solution worked. Everything ends with a crash. I checked the DDMS LOg, It was telling me to use 'Theme.AppCompat'.At last I Solved the problem by changing the android:theme="@android:style/Theme.Holo.Light.NoActionBar"Line

into android:theme="@style/Theme.AppCompat.NoActionBar"and it worked, but the the Interface was dark.

then i tried android:theme="@style/Theme.AppCompat.Light.NoActionBar" and finally got what i wanted.

After that when I Searched about 'AppCompat' on Developer Site I got This.

So I think the Solution for Android 2.2 is

<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>

And Sorry for my bad English Like Always.

2015/04/08

Source: https://stackoverflow.com/questions/8500283
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]