1

So I've tried to implement a splash screen for this android application that I'm trying to make. However, after looking at a lot of stack overflow solutions, none of them seem to fix it.

There are several problems:

  1. When the splash screen transitions to the home screen, the home screen is just white with the action bar, no "Hello World!".

  2. The splash screen itself is pretty black. Not pitch black, but it either just doesn't show the picture, or it shows like the top 25% of it. The splash screen I used is located here: http://www.onlymobilepro.com/2013/01/16/android-beginner-creating-splash-screen/ (this is only used for testing purposes)

So those are the two biggest issues. The splash screen transitions at the correct time, but with these weird glitches occuring. Here is my code.

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}

fragment_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.studyapp.MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

</RelativeLayout>

styles.xml

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@Theme.AppCompat.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

<style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowNoTitle">true</item>
</style>
</resources>

SplashActivity.java

public class SplashActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            Intent i = new Intent(SplashActivity.this, MainActivity.class);
            SplashActivity.this.startActivity(i);
            SplashActivity.this.finish();
            }
        }, 3000);
    }

fragment_splash.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView android:id="@+id/splashscreen"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:src="@drawable/splash"/>
</LinearLayout>

And finally, the Manifest.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.studyapp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" 
    android:screenOrientation="portrait"/>
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" 
    android:theme="@style/AppTheme">
    <activity
        android:name="com.example.studyapp.MainActivity"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name="com.example.studyapp.SplashActivity"
        android:label="@string/title_activity_splash" 
        android:theme="@style/Theme.Splash">    
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</manifest>

Thank you for all your help! I've been stuck on this problem for several hours.

1
  • Can you post activity_main.xml? That's what you're referencing (and setting layout as) in your Activity code.
    – Kgrover
    Mar 24, 2014 at 6:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.