项目Splash页面的开发与设计

项目Splash页面的开发与设计

首先建立一个安卓的项目,然后修改manifest.xml文件,修改应用程序的logo和显示名称,效果图如下:

 对应的代码如下:

复制代码
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 3     package="lq.wangzhen.mobilesafe"
 4     android:versionCode="1"
 5     android:versionName="1.0" >
 6     <uses-sdk
 7         android:minSdkVersion="10"
 8         android:targetSdkVersion="10" />
 9     <application
10         android:allowBackup="true"
11         android:icon="@drawable/callmsgsafe"   //设置应用程序的logo
12         android:label="@string/app_name"       //设置应用程序的名称
13         android:theme="@style/AppTheme" >
14         <activity
15             android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
16             android:name="lq.wangzhen.mobilesafe.SplashActivity"
17             android:label="@string/app_name" >
18             <intent-filter>
19                 <action android:name="android.intent.action.MAIN" />
20 
21                 <category android:name="android.intent.category.LAUNCHER" />
22             </intent-filter>
23         </activity>
24     </application>
25 </manifest>
复制代码

使用到的strings.xml文件如下:

复制代码
1 <?xml version="1.0" encoding="utf-8"?>
2 <resources>
3 
4     <string name="app_name">手机卫士</string>
5     <string name="action_settings">Settings</string>
6     <string name="hello_world">Hello world!</string>
7 
8 </resources>
复制代码

更改完成应用程序的图片以后,下面开始编写应用程序的启动界面,界面的效果图如下:

这里我们包含了一下的几个信息:

  1. 当前应用程序的版本号;
  2. 启动时的一个ProgressBar;
  3. 背景图片
  4. 设置显示为全屏幕显示,没有标题栏和状态栏

建立一个SplashActivity,对应的布局文件为:activity_splash.xml文件,然后在manifest.xml文件中配置当前的Acitivity,代码如下:

复制代码
 1 <activity
 2             android:theme="@android:style/Theme.NoTitleBar.Fullscreen"   //配置当前的Activity是全屏显示的
 3             android:name="lq.wangzhen.mobilesafe.SplashActivity"         
 4             android:label="@string/app_name" >
 5             <intent-filter>
 6                 <action android:name="android.intent.action.MAIN" />     //配置当前的Activity是应用程序的启动页面
 7 
 8                 <category android:name="android.intent.category.LAUNCHER" />
 9             </intent-filter>
10         </activity>
复制代码

编辑完成以后,完成activity_spalsh.xml文件,完成Spash页面的布局:

复制代码
 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:paddingBottom="@dimen/activity_vertical_margin"
 6     android:paddingLeft="@dimen/activity_horizontal_margin"
 7     android:paddingRight="@dimen/activity_horizontal_margin"
 8     android:paddingTop="@dimen/activity_vertical_margin"
 9     tools:context=".SplashActivity"
10     android:background="@drawable/logo2" >    //配置当前Activity的背景图片
11 
12     <TextView   //显示当前应用程序的版本号
13         android:layout_width="wrap_content"
14         android:layout_height="wrap_content"
15         android:id="@+id/tv_splash_version"
16         android:text="版本号:"
17         android:layout_alignParentRight="true"
18         android:textColor="#FF0000"
19         android:textSize="20sp"/>
20     
21     <ProgressBar   
22         android:layout_width="wrap_content"
23         android:layout_height="wrap_content"
24         android:layout_centerHorizontal="true"
25         android:layout_alignParentBottom="true"
26         android:layout_marginBottom="130dp"/>
27 
28 </RelativeLayout>
复制代码

然后在SpalshActivity类中加载以上的activity_splash.xml布局文件,然后运行程序即得到以上的效果图。

复制代码
 1 package lq.wangzhen.mobilesafe;
 2 
 3 import android.os.Bundle;
 4 import android.app.Activity;
 5 import android.content.pm.PackageInfo;
 6 import android.content.pm.PackageManager;
 7 import android.content.pm.PackageManager.NameNotFoundException;
 8 import android.view.Menu;
 9 import android.widget.TextView;
10 
11 public class SplashActivity extends Activity {
12     private TextView tv_splash_version;
13     @Override
14     protected void onCreate(Bundle savedInstanceState) {
15         super.onCreate(savedInstanceState);
16         setContentView(R.layout.activity_splash);
17         this.tv_splash_version = (TextView) this.findViewById(R.id.tv_splash_version);
18         this.tv_splash_version.setText("版本号:"+getVersion());   //设置应用程序的版本号
19     }
20     /**
21      * 取得应用的版本号
22      * @return
23      */
24     public String getVersion(){
25         PackageManager pm = getPackageManager();   //取得包管理器的对象,这样就可以拿到应用程序的管理对象
26         try {
27             PackageInfo info = pm.getPackageInfo(getPackageName(), 0);   //得到应用程序的包信息对象
28             return info.versionName;   //取得应用程序的版本号
29         } catch (NameNotFoundException e) {
30             e.printStackTrace();
31             //此异常不会发生
32             return "";
33         }
34     }
35 }
复制代码
 
 
原文地址:https://www.cnblogs.com/Leo_wl/p/3313622.html