Android 開發學習筆記:最簡單的辦法實現 APP 歡迎介面

來源:互聯網
上載者:User

標籤:android   style   blog   http   io   color   ar   os   java   

我們在開發APP的時候經常要用到歡迎介面,這裡小木推薦給大家一種簡單、快速、容易與已有項目契合的一種方法,希望可以協助到大家。

先看一下效果:

 

需要另外建立一個welcome.xml布局,只需要將背景換成匯入的圖片即可,代碼如下:

 

1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3     android:layout_width="match_parent"
4     android:layout_height="match_parent"
5     android:orientation="vertical"
6     android:background="@drawable/welcome">
7      
8  
9 </LinearLayout>

 

在對應的活動Welcome.java中寫入:

 

01 import java.util.Timer;
02 import java.util.TimerTask;
03  
04 import android.app.Activity;
05 import android.content.Intent;
06 import android.os.Bundle;
07  
08 public class Welcome extends Activity {
09  
10     @Override
11     protected void onCreate(Bundle savedInstanceState) {
12         super.onCreate(savedInstanceState);
13         setContentView(R.layout.welcome);
14         //通過一個時間控制函數Timer,在實現一個活動與另一個活動的跳轉。
15      new Timer().schedule(new TimerTask() {
16    @Override
17    public void run() {
18     startActivity(new Intent(Welcome.this,MainActivity.class));
19     finish();
20      
21    }
22   }, 3000);//這裡停留時間為1000=1s。
23  }
24  
25 }

 注意:這裡是最重要的一點,在AndroidManifest.xml中的<application下面添加第一個Activity(一定要放在第一個位置),代碼如下:

 

 

1      <activity
2             android:name="com.example.welcome.Welcome"
3             android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
4              <intent-filter>
5                 <action android:name="android.intent.action.MAIN" />
6  
7                 <category android:name="android.intent.category.LAUNCHER" />
8             </intent-filter>
9           </activity>

 然後刪除下面一個Activity中的部分:

 

 

1   <intent-filter>
2                 <action android:name="android.intent.action.MAIN" />
3  
4                 <category android:name="android.intent.category.LAUNCHER" />
5             </intent-filter>
 

 

以下是小木寫的一個demo:

http://download.csdn.net/detail/u013671350/7674525

 

Android 開發學習筆記:最簡單的辦法實現 APP 歡迎介面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.