The colors.xml and theme.xml files
First of all we need to set our project primary and secondary colors. To do that we need to input them in the colors.xml file then in theme.xml
Here my color.xml file :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple1">#3b3086</color>
<color name="purple2">#544b8f</color>
<color name="orange1">#f49d2c</color>
<color name="orange2">#edb568</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>
And here my theme.xml file :
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.PhonesGallery" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple1</item>
<item name="colorPrimaryVariant">@color/purple2</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/orange1</item>
<item name="colorSecondaryVariant">@color/orange2</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
Create a background resource file for the splash screen
Here my background resource file named splash_bg.xml :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient android:angle="270"
android:startColor="@color/purple2"
android:endColor="@color/purple1"
android:type="linear"/>
</shape>
</item>
</selector>
The animations
I created two animations files : one for the title and the subtitle and the other for the logo.
logo_anim.xml :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0%"
android:fromYDelta="-100%"
android:duration="1500"
/>
<alpha
android:fromAlpha="0.1"
android:toAlpha="1"
android:duration="1500"
/>
</set>
texts_anim.xml :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0%"
android:fromYDelta="100%"
android:duration="1500"
/>
<alpha
android:fromAlpha="0.1"
android:toAlpha="1"
android:duration="1500"
/>
</set>
The java file
Here my splash.java file :
package m.phonesgallery.phonesgallery;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
import m.phonesgallery.phonesgallery.helpers.saveState;
public class splash extends AppCompatActivity {
//XML
private TextView title,subtitle;
private ImageView logo;
//Animations
private Animation logoAnim,textsAnim;
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
//XML
title = findViewById(R.id.splashTitle);
subtitle = findViewById(R.id.splashSubtitle);
logo = findViewById(R.id.splashLogo);
//Animations
logoAnim = AnimationUtils.loadAnimation(this,R.anim.logo_anim);
textsAnim = AnimationUtils.loadAnimation(this,R.anim.texts_anim);
//to the next screen
toTheNextScreen();
}
private void toTheNextScreen(){
title.setAnimation(textsAnim);
subtitle.setAnimation(textsAnim);
logo.setAnimation(logoAnim);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(splash.this,onBoarding.class);startActivity(i);}
finish();
},3000);
}
}
Before running your app make sure that your app will run in only portrait mode by adding this line inside your activity field in AndroidManifeste.xml :
android:screenOrientation="portrait"
For more understanding watch the video