How To Create Splash Screen In Android Studio Java Code
How To Create Splash Screen In Android Studio Java Code
SplashActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window window = getWindow() ;
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
Thread splashTread = new Thread(){
@Override
public void run() {
try {
sleep(3000);
startActivity(new Intent(getApplicationContext(),MainActivity.class));
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
super.run();
}
};
splashTread.start();
}
}
activity_splash
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SplashActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="@drawable/logo"
android:scaleType="centerCrop"
android:padding="50dp"
android:layout_marginTop="220dp"/>
<ProgressBar
android:layout_width="220dp"
android:layout_height="10dp"
android:layout_gravity="center_horizontal"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:indeterminate="true"
android:progress="0"
android:layout_marginTop="100dp"
/>
</LinearLayout>
AndroidManifest.xml
<activity android:name=".MainActivity"></activity>
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Android App Gives 2 App Icons
1. Open your app AndroidManifest.xml
2. At the bottom you will find this code.
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
3. Delete this code.
Post a Comment