Create a true splash screen

前端 未结 7 559
误落风尘
误落风尘 2020-12-09 05:21

How can I make a true splash screen in Android? I don\'t want timers or delays. Just a splash screen that is shown until your application has loaded.

7条回答
  •  再見小時候
    2020-12-09 06:19

    //code for Splash code

    public class SplashScreen extends Activity {
    
        static int SPLASH_TIMEOUT = 5000;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash_layout);
    
        new Handler().postDelayed(new Runnable() {
    
            @Override
            public void run() {
                startActivity(new Intent(SplashScreen.this, MainActivity.class));
                finish();
            }
        }, SPLASH_TIMEOUT);
        }
    }
    

    Here SPLASH_TIMEOUT will define after howmuchtime your own activity should display,so change this value according to your need.

    //code for MainActivity.class

    public class MainActivity extends ActionBarActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
        }
    
    }
    

提交回复
热议问题