Reputation: 3137
I want to make a splash screen in my application, for that i need to know how to show an image in full screen. This could me made by XML or Java code ? And how? For now i just made this:
public class SplashScreen extends Activity {
private static final int STOPSPLASH = 0;
private static final long SPLASHTIME = 5000;
private Handler splashHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case STOPSPLASH:
//remove SplashScreen from view
Intent intent = new Intent(SplashScreen.this, jetpack.class);
startActivity(intent);
break;
}
super.handleMessage(msg);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
Message msg = new Message();
msg.what = STOPSPLASH;
splashHandler.sendMessageDelayed(msg, SPLASHTIME);
}
}
How can be this splash_screen.xml ? Thank you for your help.
Upvotes: 21
Views: 62147
Reputation: 480
just using super.onCreate
and setConntentView
code :
/** Hiding Title bar of this activity screen */
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
/** Making this activity, full screen */
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
Upvotes: 0
Reputation: 445
<style name="FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
Upvotes: 2
Reputation:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/image" />
</LinearLayout>
and add the below code before setContentView(R.layout.splash_screen);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Upvotes: 32
Reputation: 3772
The best way to show a full screen splash activity is by putting this line in your manifest under activity tag
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
You can use other themes as well
Theme.Black.NoTitleBar.Fullscreen
Theme.NoTitleBar.Fullscreen
<activity
android:name="com.example.SplashActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For Latest Api Lollipop and above
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
Define this theme for the splash activity and provide it in manifest
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"
Upvotes: 36
Reputation: 3282
If R.layout.splash_screen included an image with height and width set to fill_parent or match_parent (depending on version). It will fill the screen
Upvotes: 2