編輯:關於Android編程
本文實例講述了Android開發基礎之創建啟動界面Splash Screen的方法。分享給大家供大家參考。具體如下:
啟動界面Splash Screen在應用程序是很常用的,往往在啟動界面中顯示產品Logo、公司Logo或者開發者信息,如果應用程序啟動時間比較長,那麼啟動界面就是一個很好的東西,可以讓用戶耐心等待這段枯燥的時間。
Android 應用程序創建一個啟動界面Splash Screen非常簡單。比如創建一個工程MySample,主Acitity就叫MySample,創建另一個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開發本地及網絡Mp3音樂播放器(七)循環模式與專輯倒影
實現功能:順序播放隨機播放單曲循環PlayActivity(獨立音樂播放界面)的專輯封面圖片的倒影效果另外,我打算開始找工作,如果沈陽或周邊城市公司有意,也請與我聯系。實
android界面布局之實現文本塊布局效果示例
復制代碼 代碼如下:package cn.aibow.android.layoutdemo1;import android.os.Bundle;import androi
android:如何用一天時間,寫出“飛機大戰”這樣的游戲!(無框架-SurfaceView繪制)
序言作為一個android開發者,時常想開發一個小游戲娛樂一下大家,今天就說說,我是怎麼樣一天寫出一個簡單的“飛機大戰”的.體驗地址:http://www.wandouj
Android Material Design新UI控件使用大全 二
序言上一篇中我們介紹了幾個簡單的新UI控件,相信很多小伙伴對Materil Design的視覺效果有了一定的了解,今天我們就繼續介紹其他幾個控件的玩兒法,讓我們一探Mat