After each Android application is started, a Splash startup interface is displayed, showing the product LOGO, company LOGO, or developer information. If the application starts for a long time, the startup interface is a good thing, so that users can wait for this boring time.
- Create a Splash Interface
Highlight the product LOGO, product name, and main features;
Indicates the product version information;
Indicate company or developer information;
The background image can also be replaced by the background color;
- What can I do besides waiting?
Most Splash interfaces wait for a certain period of time and then switch to the next interface;
In fact, during this period, you can check the system status, such as whether the network is connected and whether the power supply is sufficient;
Or, pre-load the relevant data;
To make the startup interface display time fixed, you need to calculate the time required to execute the preceding preprocessing tasks. The time required to start the interface SLEEP = fixed time-the time required to start the preprocessing task.
- Source code example (take the Android client of Wordpress as an example)
AndroidMenifest. xml <activity android:icon="@drawable/app_icon"
android:screenOrientation="portrait"
android:name=".splashScreen"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
SplashScreen. java
package org.wordpress.android;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;
import android.widget.TextView;
public class splashScreen extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().setFormat(PixelFormat.RGBA_8888);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
setContentView(R.layout.splashscreen);
//Display the current version number
PackageManager pm = getPackageManager();
try {
PackageInfo pi = pm.getPackageInfo("org.wordpress.android", 0);
TextView versionNumber = (TextView) findViewById(R.id.versionNumber);
versionNumber.setText("Version " + pi.versionName);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
new Handler().postDelayed(new Runnable() {
public void run() {
/* Create an Intent that will start the Main WordPress Activity. */
Intent mainIntent = new Intent(splashScreen.this, wpAndroid.class);
splashScreen.this.startActivity(mainIntent);
splashScreen.this.finish();
}
}, 2900); //2900 for release
}
}
Splashscreen. xml
<! --
Android: gravity refers to the element itself. The text of the element itself is displayed on the left side by changing the attribute settings.
Android: layout_gravity is relative to its parent element, indicating where the element is displayed.
-->
<LinearLayout android: id = "@ + id/LinearLayout01"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: gravity = "center | center"
Android: background = "@ drawable/home_gradient"
Android: orientation = "vertical">
<! --
Android: scaleType controls how images are resized/moved to match the size of ImageView.
CENTER_INSIDE/centerInside shows the entire content of the image in the center. The image length/width is equal to or less than the View length/width by proportional reduction or the original size.
-->
<ImageView android: layout_marginTop = "-60dip"
Android: paddingLeft = "20dip"
Android: paddingRight = "20dip"
Android: scaleType = "centerInside"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: id = "@ + id/wordpress_logo"
Android: src = "@ drawable/wordpress_home">
</ImageView>
<! --
Android: typeface Font Style
-->
<TextView android: text = "@ + id/TextView01"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_marginTop = "20dip"
Android: typeface = "serif"
Android: shadowDx = "0"
Android: shadowDy = "2"
Android: shadowRadius = "1"
Android: shadowColor = "# FFFFFF"
Android: textColor = "#444444"
Android: textSize = "20dip"
Android: id = "@ + id/versionNumber"
Android: gravity = "bottom">
</TextView>
</LinearLayout>