Splash screen in Android Application

前端 未结 3 1145
轮回少年
轮回少年 2020-12-16 07:09

I am modifying an open source application and want to add a splash screen to it, Can some one help me in it?

When the application starts a black screen appears for 2

3条回答
  •  盖世英雄少女心
    2020-12-16 07:47

    Use class SplashScreen as under

    public class Splashscreen extends Activity {
    
    private static final int SPLASH_DISPLAY_TIME = 3000; /* 3 seconds */
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
    
        new Handler().postDelayed(new Runnable() {
    
            public void run() {
    
                Intent mainIntent = new Intent(Splashscreen.this,
                        MainActivity.class);
                Splashscreen.this.startActivity(mainIntent);
    
                Splashscreen.this.finish();
                overridePendingTransition(R.anim.mainfadein,
                        R.anim.splashfadeout);
            }
        }, SPLASH_DISPLAY_TIME);
    }
    

    }

    **Add mainfadein.xml & splashfadeout.xml in res->anim folder

    mainfadein.xml**

        
    
    
    

    splashfadeout.xml

    
    
    
    

    and add splash.xml just Add an ImageView and set its background as screen & add image of urchoice in layout

    And make Splashscreen class as Launcher and make all other class as HOME in manifest file

提交回复
热议问题