Search code examples
androidanimationtextviewstartup

Animation on startup


On my splash screen, i'd like to make a TextView fade in, 5 seconds later to fade out and after it has faded out i'd like it to open a new xml file. Can someone help me out? I'm kinda new to coding so maybe a bit of code would be fantastic! Kind regards!


Solution

  • Try this in oncreate() :

         //First start animation for fadein
        Animation animation = AnimationUtils.loadAnimation(this,R.anim.abc_fade_in);
        yourtextView.startAnimation(animation);
    
        // The thread to wait for 5 seconds
        mSplashThread =  new Thread(){
            @Override
            public void run(){
                try {
                     Thread.sleep(5000);
                }
                catch(InterruptedException ex){                    
                } finally{
                //start animation for fadeout after 5 seconds
                Animation animation = AnimationUtils.loadAnimation(YourClass.this,R.anim.abc_fade_out);
                yourtextView.startAnimation(animation);
                //Start next activity
                Intent intent = new Intent(YourClass.this,MainActivity.class);
                startActivity(intent);  
                }     
            }
        };
        mSplashThread.start();