splash screen application and hide action bar
why not add to the manifest the theme of the first activity to exclude the action bar, and maybe even the notification bar?
something like:
<application android:allowBackup="true" android:icon="@drawable/lojacidadao" android:label="@string/app_name" android:theme="@style/AppTheme"> <activity android:name="com.example.basicmaponline.Intro" android:screenOrientation="portrait" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> ...
This should work if you extend the normal Activity
class.
If your Activity extends AppCompatActivity
instead, use this theme for example:
<style name="AppTheme.Splash" parent="@style/Theme.AppCompat.NoActionBar"> <item name="android:windowFullscreen">true</item> <item name="android:windowContentOverlay">@null</item> </style>
meaning :
<activity ... android:theme="@style/AppTheme.Splash" > ...
BTW, the reason you have the action bar is because you have set the default theme to have it, in the application tag, so it's not an activity before yours, it's really your own splash activity.
if your build target sdk 5.0 or over (AppTheme style is Theme.AppCompat.Light.DarkActionBar.)
<activity android:name=".Splash" android:label="@string/app_name" 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>
You're problem are these lines
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);getActionBar().hide();
They are not needed as there should be no ActionBar
to call at all, the splash screen does not use one and should be a completely separate Activity
than your others.
You need two Activities
. One for the Splash Screen with it's own layout. The 2nd is for the main Activity
, which can be a login screen or welcome screen etc.
The splash screen class should look like this
public class SplashScreen extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.yourlayoutfile); Thread loading = new Thread() { public void run() { try { sleep(5000); Intent main = new Intent(SplashScreen.this, Main.class); startActivity(main); } catch (Exception e) { e.printStackTrace(); } finally { finish(); } } }; loading.start();}}
XML File
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/LinearLayout1" android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:orientation="vertical" tools:context=".SplashScreen" >// if not using an image replace with whatever is to be shown on the splash screen<ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/logo" /></LinearLayout>
Now the 2nd Activity
has the layout with the ActionBar
etc.