Membuat Splash Screen

Layout
<ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="145dp" />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/img1"
        android:layout_above="@+id/progressBar"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="78dp"
        android:src="@mipmap/ic_launcher"/>


Java
public class MainActivity extends AppCompatActivity {
    private long ms = 0, splashTime = 3500;
    private boolean splashActive = true, paused = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Thread mythread = new Thread() {
            public void run() {
                try {
                    while (splashActive && ms < splashTime) {
                        if (!paused)
                            ms = ms + 100;
                        sleep(100);
                    }
                } catch (Exception e) {
                } finally {
                    Intent intent = new Intent(MainActivity.this, Main2Activity.class);
                    startActivity(intent);
                    finish();
                }
            }
        };
        mythread.start();
    }
}

Comments

Popular posts from this blog

Membuat Toast

Mengenal Satuan Ukuran sp dan dp di Android

Menjalankan Aplikasi Android