您的位置:首页 > 移动开发 > Android开发

Android————制作启动页面

2013-03-05 10:49 387 查看
1、制作三张启动图片都命名为splash.png,分辨率为240*320、320*480、480*800,分别放置在drawable-ldpi、drawable-mdpi、drawable-hdpi文件夹中。

2、在layout文件夹中创建一个activity_splash.xml文件,内容如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"  android:layout_height="fill_parent"
android:gravity="bottom|center"  android:orientation="vertical"
android:background="@drawable/splash">

<TextView
android:id="@+id/splash_VerNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dip"
android:gravity="bottom"
android:textSize="20dip" />

</LinearLayout>


3、在src文件夹的架包中新建SplashActivity,代码如下

package com.lxh.androideater;

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.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.TextView;

public class SplashActivity extends Activity {

//------------------------------------------ 变量 ------------------------------------------
//显示版本号
TextView tViewVerNumber = null;
//延时跳转
Handler handler = null;
JustIntoMainActivityRunnable gotoMainR = null;

//------------------------------------------ 方法 ------------------------------------------
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//设置要显示的布局文件
setContentView(R.layout.activity_splash);
try  {
//获取架包管理对象
PackageManager pm = getPackageManager();
//回去本项目的包信息对象
PackageInfo pi = pm.getPackageInfo("com.lxh.androideater", 0);
//得到activity_splash.xml中显示版本号的TextView
tViewVerNumber = (TextView) findViewById(R.id.splash_VerNumber);
//pi.versionName要显示的版本信息,
//即AndroidManifest.xml中的   android:versionName="1.0.0"  数据
tViewVerNumber.setText("版本号: " + pi.versionName);

} catch (Exception e) {
// TODO: handle exception
Log.e("Error——Splash", e.getMessage());
e.printStackTrace();
}
handler = new Handler();
gotoMainR = new JustIntoMainActivityRunnable();
//2500毫秒后执行JustIntoMainActivityRunnable对象的run()方法
handler.postDelayed(gotoMainR, 250000);
}

//------------------------------------------ 类 ------------------------------------------
/**
*  进入MainActivity页面
*/
class JustIntoMainActivityRunnable implements Runnable {

@Override
public void run() {
// TODO Auto-generated method stub
//创建一个Intent对象
Intent intent = new Intent();
//设置要跳转的页面对象
intent.setClass(SplashActivity.this, MainActivity.class);
//跳转到MainAcitivity页面
startActivity(intent);
//把本页面从栈中弹出
SplashActivity.this.finish();
}

}

}


4、 修改AndroidManifest.xml文件,将启动界面Activity改为默认启动,并且设置标题栏不可见。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lxh.androideater"
android:versionCode="1"
android:versionName="1.0.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />

<application
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.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
</activity>

</application>

</manifest>


5、显示效果如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: