Štěpán Záliš Štěpán Záliš - 5 months ago 30
Android Question

Splash screen Android

I am beginner and I would like to show splash screen, but my boss wants to use Fragment. I do not know how to implement it in my MainActivity. I know that I have to use handler with time and stack layout, but I have not found how.
Thanks

Answer

If you want to add a Splash Screen as a Fragment inside your MainActivity

  1. Add a FrameLayout to your MainActivity, inside the FrameLayout, make a Layout for your Views, and insert a Fragment which holds your SplashScreen Display (Make sure your Fragment is in the bottom of the MainActivity, so that its displayed over your layout)

Example

<FrameLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent">

   <LinearLayout 
      android:layout_width="match_parent"
      android:layout_height="match_parent">

         //Your UI goes here        

   </LinearLayout>


  <Fragment
      Your Fragment with Splash Screen Goes here 
   />
</FrameLayout>



  1. In side your FragmentActivity do this

     new Handler()..postDelayed(new Runnable() {
        @Override
        public void run() { 
    
           Intent intent = getActivity().getIntent();
           getActivity().finish();
           startActivity(intent);
    
      }
    },2000);
    
Comments