Splash screen in Android Application

前端 未结 3 1136
轮回少年
轮回少年 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:46

    Splash activity

    public class LaunchScreen extends Activity {
    
      public static final long TIME = 3000;
    
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.logo);
    
        Protocol.getInstance(this);
    
        Thread welcomeThread = new Thread() {
    
            @Override
            public void run() {
                try {
                    sleep(TIME);
                } catch (Exception e) {
                    Log.e(getClass().getName(), e.toString());
                } finally {
                    startActivity(new Intent(LaunchScreen.this,MainScreen.class));
                    finish();
                }
            }
        };
        welcomeThread.start();
      }
    }
    

    logo.xml file:

      
    
    
    
    

    in AndroidManifest :

    activity android:name=".LaunchScreen">
            
                
                
            
        
        
    

提交回复
热议问题