制作效果如图:
源码下载:http://yunpan.cn/cyRPy5ratJxLQ 访问密码 90ac
1 创建工程 应用名称:手机卫士 工程名称:MoblieSafe 第一个Activitry:SplashActivity
2 设置布局文件,activity_splash.xml,设置背景图片,设置版本信息,设置进度条
3 动态获取apk版本信息--版本号设置到界面
activity_splash.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/luncher_bg"
tools:context="com.itheima.mobilesafe.SplashActivity" >
<TextView
android:id="@+id/tv_splash_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:shadowColor="#ff0000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="1"
android:text="版本号1.0"
android:textColor="#000000"
android:textSize="20sp" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_splash_version"
android:layout_centerHorizontal="true" />
</RelativeLayout>
SplashActivity.java
package com.itheima.mobilesafe;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.widget.TextView;
public class SplashActivity extends Activity {
private TextView tv_splash_version;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
tv_splash_version =(TextView) findViewById(R.id.tv_splash_version);
tv_splash_version.setText("版本号"+getVersionName());
}
/**
* 得到应用程序的版本名称
* @return 版本名称
*/
private String getVersionName(){
//apk管理者
PackageManager pm = getPackageManager();
try {
//apk功能清单文件信息
PackageInfo info = pm.getPackageInfo(getPackageName(), 0);
return info.versionName;
} catch (NameNotFoundException e) {
e.printStackTrace();
return "";
}
}
}
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.itheima.mobilesafe"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".SplashActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
源码下载:http://yunpan.cn/cyRPy5ratJxLQ 访问密码 90ac