1、create a startup image splash.png and place it in the res-> drawable-hdpi folder.
2. Create a layout file splash. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: Background = "@ drawable/Splash">
<Textview
Android: Id = "@ + ID/versionnumber"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_alignparentbottom = "true"
Android: layout_alignparentright = "true"
Android: layout_marginbottom = "26dp"
Android: layout_marginright = "52dp"
Android: text = "version 1.0"
Android: textcolor = ""/>
</Relativelayout>
Here we use the image created in the previous step as the background image of the startup interface, and then the current program version number is displayed at the bottom of the interface.
3. Create a splashactivity and add the following code to oncreate:
PackageManager pm = getPackageManager();try { PackageInfo pi = pm.getPackageInfo("com.lyt.android", 0); TextView versionNumber = (TextView) findViewById(R.id.versionNumber); versionNumber.setText("Version " + pi.versionName);} catch (NameNotFoundException e) { e.printStackTrace();}new Handler().postDelayed(new Runnable(){@Overridepublic void run() { Intent intent = new Intent(SplashActivity.this,SplashScreenActivity.class); startActivity(intent); SplashActivity.this.finish();}}, 2500);
4. Modify the manifest file, change the activity on the startup interface to start by default, and set the title bar to be invisible.
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "com. example. sinaweibo"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
<Uses-SDK
Android: minsdkversion = "8"
Android: targetsdkversion = "15"/>
<Application
Android: icon = "@ drawable/ic_launcher"
Android: Label = "@ string/app_name"
Android: theme = "@ Android: style/theme. notitlebar">
<Activity
Android: Name = ". mainactivity"
Android: Label = "@ string/title_activity_main">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
<Activity
Android: Name = ". mainactivity1"
Android: Label = "@ string/title_activity_main_activity1">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
</Application>
</Manifest>
In this way, after the application is opened, wait 2.5 seconds to enter the second activity mainactivity.