Membuat Splash Screen di Android Studio
Buatlah Activity Baru dengan nama Splash_Screen, kemudian buatlah layout untuk activity splash_screen nya, misalnya menambahkan sebuah gambar dan progressbar
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:theme="@android:style/Theme.NoTitleBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#0074b9"
tools:context="giviews.id.splash.Splash_Screen">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="247dp"
app:srcCompat="@drawable/favicon" />
<ProgressBar
android:id="@+id/progressBar2"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="124dp" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:theme="@android:style/Theme.NoTitleBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#0074b9"
tools:context="giviews.id.splash.Splash_Screen">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="247dp"
app:srcCompat="@drawable/favicon" />
<ProgressBar
android:id="@+id/progressBar2"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="124dp" />
</RelativeLayout>
kemudian untuk script javanya silakan masukan kode berikut:
package giviews.id.splash;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import static android.view.Window.FEATURE_NO_TITLE;
public class Splash_Screen extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash__screen);
Thread myThread = new Thread() {
@Override
public void run() {
try {
sleep(3000);
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
myThread.start();
}
}
Terakhir sesuikan kode di AndroidManifest anda seperti ini
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="giviews.id.splash">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Splash_Screen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:theme="@style/Base.V7.Theme.AppCompat"
tools:ignore="DuplicateActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="giviews.id.splash.MainActivity" />
</activity>
</application>
</manifest>
Silakan jalankan aplikasi anda, jika ada yang error bisa ditanyakan pada kolom komentar dibawah, terimakasih sudah berkunjung ke blog ini.
Belum ada Komentar untuk "Membuat Splash Screen di Android Studio"
Posting Komentar