Okay so what I'm wanting to do is add an image to my splash screen, so it displays the image before the app starts. I think(?) I found the right code to actually do the splash screen but I can't get the image in it. From what I've read it needs to be in a png file, which it is but how do I move it from a file on my computer to the code, and then where do I go from there?
-
`I think(?) I found the right code to actually do the splash screen` Mind explaining what you've tried. This will give us a starting place to help explain how to continue from where you are. – Code-Apprentice Oct 26 '14 at 04:21
-
http://stackoverflow.com/questions/5486789/how-do-i-make-a-splash-screen-in-android this is the code that i've tried – Oct 26 '14 at 04:25
-
1Then all you need to do is put your image in the `app/main/src/res/drawable` folder and name it `spalsh.png`. I strongly encourage you to read about the directory structure of an Android Studio project. – Code-Apprentice Oct 26 '14 at 04:30
-
@AhmadVatani Please post an answer that summarizes your solution. – Code-Apprentice May 01 '20 at 16:43
2 Answers
Assuming that you have exactly the code given in How do I make a splash screen? then you simply need to save your picture as splash.png
in the app/main/src/res/drawable
folder. Be sure to clean and rebuild your project before running it. Note that you can give the PNG any name you want. Just change splash
in android:src="@drawable/splash"
to match the name you use. Also, I strongly encourage you to learn about the directory structure in an Android Studio project.

- 1
- 1

- 81,660
- 23
- 145
- 268
My post here answers this question.
To "move" the image from a file to your code, you need to place it into your drawable folder, then refrence it somewhere by using
@drawable/image
To better understand how to change the splash screen image please read below.
Add Splash Screen Image
First you need a splash screen image. Because Android devices come in various resolutions, you may want to ship several splash screens as described in Google's Best Practices for Supporting Multiple Screens. For simplicity, we'll just ship one here that is 480x800. It should support most phone sizes pretty well, and Android will scale it as best it can.
Add the the image/gif you want into your Resources\Drawable
You need to define the splash screen in your layout.xml file
<?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 id="@+id/splashscreen" android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/splash"
android:layout_gravity="center"/>
<TextView android:layout_width="fill_parent" <!-- Not needed->-->
android:layout_height="wrap_content"
android:text="Hello World, splash"/> <!--Not Needed -->
</LinearLayout>
And your activity:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class Splash extends Activity {
/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 1000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splashscreen);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Splash.this,Menu.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
}

- 1
- 1

- 391
- 2
- 9
-
Is that C#? I think a Java answer will be more helpful since the OP tagged the question with `android-studio`. – Code-Apprentice Oct 26 '14 at 04:24
-
Yes, the last part is in C#, I nearly forgot to mention that this requires [Xamarin](http://xamarin.com/download) to use. I'll correct the code to work in android studio – Karma Hunter Oct 26 '14 at 04:29
-
2If you want to save the time, there is already a Java answer here on SO. The OP linked to it in the comments to the question and I have voted to close as a duplicate. – Code-Apprentice Oct 26 '14 at 04:33