The incorrect implementation of the Android boot screen may cause the user to wait for a long time, or a black and white screen may appear. Here is a brief demonstration of how to correctly implement the Android boot screen.
The demo is divided into the following steps:
- Create a splash_background.xml file in the res/drawable folder.
- Edit res/values/
- Create java/.../SplashActivity
- Edit manifests/
1. Create splash_background.xml file in the res/drawable folder
Adjust the gravity and size of the bitmap image according to your needs.
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:andro> <item android:drawable="@color/colorPrimary"/> <item android:gravity="center" android:width="100dp" android:height="100dp"> <bitmap android:gravity="fill_horizontal|fill_vertical" android:src="@drawable/logo"/> </item> </layer-list>
2. Edit res/values/
The style here is used for the launch screen. This is to hide the action bar when the screen is launched.
<resources> <!-- Base application theme. --> <style name="AppTheme" parent=""> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="SplashTheme" parent=""> <item name="android:windowBackground">@drawable/splash_background</item> </style> </resources>
3. Create java/.../SplashActivity
Once the App starts, SplashActivity will be started and then transferred to MainActivity.
package ; import ; import ; import .; public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); //switch from splash activity to main activity Intent intent = new Intent(this, ); startActivity(intent); finish(); } }
4. Edit manifests/
Add a new splash screen activity in the manifest file.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:andro package=""> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="goodSplash" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name="" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="" /> <category android:name="" /> </intent-filter> </activity> <activity android:name=""></activity> </application> </manifest>
Sample source code address:/mrjoedang/goodSplash
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.