【Android】欢迎界面的创建方法

1.将splash.png放置在res->drawable文件夹中

2.新建布局文件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="版本号:1.0" />

</RelativeLayout>

3.新建Activity

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

    /*
     * 欢迎界面
     */
public class SplashActivity extends Activity {

    private TextView versonTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    versonTextView = (TextView) findViewById(R.id.versionNumber);
    try {
        PackageManager packageManager = getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(
            getPackageName(), 0);
        versonTextView.setText("版本号:" + packageInfo.versionName);
    } catch (Exception e) {

    }
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
        // TODO Auto-generated method stub
        Intent intent = new Intent(SplashActivity.this,
            MainActivity.class);
        startActivity(intent);
        SplashActivity.this.finish();
        }
    }, 2000);
    }

}
4.注册Activity并设为默认启动
posted @ 2013-12-24 09:45  NúllPòinterExcêptīon  阅读(195)  评论(0编辑  收藏  举报