码迷,mamicode.com
首页 > 移动开发 > 详细

【Android】应用启动画面

时间:2015-07-15 10:48:33      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

  几乎所有的Android应用程序都会有一个启动画面,展示自己的LOGO,本版信息,或者更人性化一点的,在很长的加载信息中,变换一些显示的文字等,让无聊的等待时间添加点调味剂。

  具体实现来说,应该创建一个没有Title的Activity,显示图片,文字。其中创建新的线程去加载数据,检测设备的良好等,等一切就绪的时候启动新的Activity。

 

代码如下 

 

  AndroidManifast.xml

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dnfscripts"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity 
            android:name="com.example.dnfscripts.LoadActivity"
            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="com.example.dnfscripts.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 

其中,声明两个Activity,一个用来作为启动画面,另外一个是启动之后,显示的主画面。

android:screenOrientation="portrait"    //屏幕始终纵向

                                       "landscape" //屏幕始终横向

android:theme="@android:style/Theme.NotitleBar" //屏幕没有标题栏

load.xml

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:gravity="center|center"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/index" >


</LinearLayout>

 

该load.xml是启动Activity的样式表达,其中

android:background="@drawable/load"  //设置load.png图片为背景图

 

LoadActivity.java

 

 

package com.example.dnfscripts;

import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Handler;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class LoadActivity extends Activity {

    private static final int LOAD_DISPLAY_TIME = 5000;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFormat(PixelFormat.RGBA_8888);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
        setContentView(R.layout.activity_load);
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                
                /* Create an Intent that will start the Main WordPress Activity. */
                 Intent mainIntent = new Intent(LoadActivity.this, MainActivity.class);
                 LoadActivity.this.startActivity(mainIntent);
                 LoadActivity.this.finish();
            }
        },LOAD_DISPLAY_TIME); //5000 for release
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        // TODO Auto-generated method stub
        super.onCreateContextMenu(menu, v, menuInfo);
    }

}

 

  其中,Handler().postDelayed(Runnable r, long delayMillis)

      //Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.

  现在的代码只实现了很简单Load页面的显示。

 

 

 

 

 

【Android】应用启动画面

标签:

原文地址:http://www.cnblogs.com/chen-lhx/p/4647477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!