Android開發(fā)基礎之創(chuàng)建啟動界面Splash Screen的方法
本文實例講述了Android開發(fā)基礎之創(chuàng)建啟動界面Splash Screen的方法。分享給大家供大家參考。具體如下:
啟動界面Splash Screen在應用程序是很常用的,往往在啟動界面中顯示產(chǎn)品Logo、公司Logo或者開發(fā)者信息,如果應用程序啟動時間比較長,那么啟動界面就是一個很好的東西,可以讓用戶耐心等待這段枯燥的時間。
Android 應用程序創(chuàng)建一個啟動界面Splash Screen非常簡單。比如創(chuàng)建一個工程MySample,主Acitity就叫MySample,創(chuàng)建另一個Activity叫 SplashScreen,用于顯示啟動界面,資源文件為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();
// 啟動主應用
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>
在這里負責注冊兩個活動。把負責管理啟動界面Splash Screen的活動Activity作為應用程序的主活動,然后在SplashScreen中負責啟動MyApp。
希望本文所述對大家的Android程序設計有所幫助。
相關文章
Android基于socket實現(xiàn)的簡單C/S聊天通信功能
這篇文章主要介紹了Android基于socket實現(xiàn)的簡單C/S聊天通信功能,結合實例形式分析了Android使用socket實現(xiàn)客服端與服務器端數(shù)據(jù)的發(fā)送與接收處理技巧,需要的朋友可以參考下2016-10-10
Android?無障礙服務?performAction?調用過程分析
這篇文章主要介紹了Android?無障礙服務?performAction?調用過程分析,無障礙服務可以模擬一些用戶操作,無障礙可以處理的對象,通過類?AccessibilityNodeInfo?表示,通過無障礙服務,可以通過它的performAction方法來觸發(fā)一些action2022-06-06
事件是一種有用來收集用戶與應用程序互動數(shù)據(jù)的互動組件,如按鍵或觸摸屏等放置事件,因為每個事件從Android框架維護事件隊列先入先出(FIFO)基礎上的隊列??梢栽诔绦蛑胁东@這些事件,按要求并采取適當?shù)膭幼?/div> 2023-02-02
Android編程布局(Layout)之AbsoluteLayout用法實例分析
這篇文章主要介紹了Android編程布局(Layout)之AbsoluteLayout用法,結合實例形式簡單分析了Android絕對布局AbsoluteLayout的實現(xiàn)方法,需要的朋友可以參考下2015-12-12最新評論

