欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開發(fā)基礎(chǔ)之創(chuàng)建啟動(dòng)界面Splash Screen的方法

 更新時(shí)間:2015年10月16日 14:22:34   作者:白羽雕弓  
這篇文章主要介紹了Android開發(fā)基礎(chǔ)之創(chuàng)建啟動(dòng)界面Splash Screen的方法,以實(shí)例形式較為詳細(xì)的分析了Android定制啟動(dòng)界面的布局及功能實(shí)現(xiàn)相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Android開發(fā)基礎(chǔ)之創(chuàng)建啟動(dòng)界面Splash Screen的方法。分享給大家供大家參考。具體如下:

啟動(dòng)界面Splash Screen在應(yīng)用程序是很常用的,往往在啟動(dòng)界面中顯示產(chǎn)品Logo、公司Logo或者開發(fā)者信息,如果應(yīng)用程序啟動(dòng)時(shí)間比較長,那么啟動(dòng)界面就是一個(gè)很好的東西,可以讓用戶耐心等待這段枯燥的時(shí)間。

Android 應(yīng)用程序創(chuàng)建一個(gè)啟動(dòng)界面Splash Screen非常簡單。比如創(chuàng)建一個(gè)工程MySample,主Acitity就叫MySample,創(chuàng)建另一個(gè)Activity叫 SplashScreen,用于顯示啟動(dòng)界面,資源文件為splash.xml。至于如何制作SplashSceen界面,這不是本文章要討論的東西,就 此略過。

SplashScreen的代碼如下:

package com.ctoof.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
public class SplashScreen extends Activity {
 protected boolean _active = true;
 protected int _splashTime = 5000;
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.splash);
  Thread splashTread = new Thread() {
   @Override
   public void run() {
    try {
     int waited = 0;
     while(_active && (waited < _splashTime)) {
      sleep(100);
      if(_active) {
       waited += 100;
      }
     }
    } catch(InterruptedException e) {
     // do nothing
    } finally {
     finish();
     // 啟動(dòng)主應(yīng)用
     startActivity(new Intent("com.ctoof.android.MySample.MyApp"));
     stop();
    }
   }
  };
  splashTread.start();
 }
 @Override
 public boolean onTouchEvent(MotionEvent event) {
  if (event.getAction() == MotionEvent.ACTION_DOWN) {
   _active = false;
  }
  return true;
 }
}

然后在AndroidMainfest.xml中修改代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.ctoof.android"
  android:versionCode="1"
  android:versionName="1.0">
 <application android:icon="@drawable/icon" android:label="@string/app_name">
  <activity android:name=".SplashScreen"
     android:label="@string/app_name">
   <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
  </activity>
  <activity android:name=".MyApp">
   <intent-filter>
    <action android:name=" com.ctoof.android. MySample.MyApp " />
    <category android:name="android.intent.category.DEFAULT" />
   </intent-filter>
  </activity>
 </application>
 <uses-sdk android:minSdkVersion="4" />
</manifest>

在這里負(fù)責(zé)注冊(cè)兩個(gè)活動(dòng)。把負(fù)責(zé)管理啟動(dòng)界面Splash Screen的活動(dòng)Activity作為應(yīng)用程序的主活動(dòng),然后在SplashScreen中負(fù)責(zé)啟動(dòng)MyApp。

希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論