2

I'm trying to create splash screen without action bar.
Firstly before created splash screen, action bar in main activity and when I create splash screen, action bar comes to splash screen and main activity is full screen. I searched method like getwindow(), getActionBar(), but when I use these method program says to me unfortunately stopped. So what I'm missing?

How can I avoid actionBar in splash screen?

My code:

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    

    setContentView(R.layout.splash_item);
    
    Thread th=new Thread(){
        public void run(){
            try {
                sleep(4000);
                Intent intent=new Intent(MainActivity.this,SplashScreen.class);
                startActivity(intent);
                
            } catch (Exception e) {
                e.printStackTrace();
            }
            finally{
                finish();
            }
        }
    };
    th.start();
}

MANİFEST:

  <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
     <activity
        android:name=".SplashScreen"
        android:label="@string/app_name" 
        >
        <intent-filter>
            <action android:name="android.intent.action.SPLASHSCREEN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>
Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
Mert Kimyonşen
  • 47
  • 1
  • 3
  • 9

6 Answers6

5

First, import the support library in the top of your app:

import android.support.v7.app.ActionBarActivity;

and change your code as follows:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.splash_item);
    getSupportActionBar().hide();
}
Robb1
  • 4,587
  • 6
  • 31
  • 60
Josef
  • 442
  • 7
  • 16
4

Using AppCompat for being supported for all versions:

<activity 
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
1
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

Put that before your setContentView(...), should get the job done.

The Hungry Androider
  • 2,274
  • 5
  • 27
  • 52
1

For Android 3.0 or higher use ActionBarAPI#hide
For lower versions you will need to use Android Support Library. Use ActionBar as

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

Ref docs

Also if your requirement in static, then you can choose a theme for your activity that dos not have actionbar such as

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

You can do this as:

<activity android:theme="@android:style/Theme.Holo.Light.NoActionBar" 
  android:name=".name_here" 
  android:label="@string/app_name" >
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
spidergears
  • 194
  • 11
0

use a style without actionbar, also in your splash screen activity java extend Activity and make the splash screen your MAIN activity and in this activity you call an Intent to open your MainActivity after some seconds

 <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
    </activity>
        <activity android:theme="@android:style/Theme.Holo.Light.NoActionBar"
        android:name=".SplashScreen"
        android:label="@string/app_name" >
       <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Example: In your SplashScreen activity write this code. This will open your MainActivity after 2 seconds.

  new Handler().postDelayed(new Runnable()
  {
    public void run()
    {
      Intent localIntent = new Intent(SplashScreen.this, MainActivity.class);
      SplashScreen.this.startActivity(localIntent);
      SplashScreen.this.finish();
    }
  }, 2000L);
Cristian Olaru
  • 487
  • 5
  • 20
0

This is the simplest method.

@Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
}

where R.layout.activity_main is replaced by your layout activity e.g. activity_splash