国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android開發基礎之創建啟動界面Splash Screen的方法

2020-04-11 11:22:56
字體:
來源:轉載
供稿:網友

本文實例講述了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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 五家渠市| 澳门| 宜阳县| 六盘水市| 资溪县| 高阳县| 沙田区| 叙永县| 平陆县| 湘潭市| 嘉义县| 东台市| 张家界市| 开化县| 奉贤区| 织金县| 东方市| 寻甸| 黄陵县| 孝感市| 清丰县| 苏州市| 子长县| 印江| 张家界市| 丹巴县| 游戏| 团风县| 金昌市| 宝坻区| 丹阳市| 会同县| 临泽县| 沙湾县| 香港| 涞源县| 永川市| 成武县| 衡水市| 青州市| 桃源县|