1

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!

h-beneuh
  • 35
  • 4
  • if you're new to coding, a search for code examples conducted by you yourself would help you most. Especially as you then can compare the different solutions. – planetmaker Nov 23 '15 at 13:28

1 Answers1

1

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();
Akshay Bhat 'AB'
  • 2,690
  • 3
  • 20
  • 32
  • Thank you for your response! I get no errors, except when you define the animations. in (this,R.anim.abc_fade_out), Android Studio gives an error by 'this', then it says: Wrong 1st argument type. Found: 'java.lang.Thread', required: 'android.content.Context' loadAnimation (android.content.Context, int) in AnimationUtils cannot be applied to (anonymous java.lang.Thread, int) Any idea how to solve this? – h-beneuh Nov 23 '15 at 13:41
  • since it is inside run() method, instead of 'this', use 'YourClassName.this' – Akshay Bhat 'AB' Nov 24 '15 at 07:14