close
一般Logo跳到Main的時候都會延遲個一秒到兩秒,為的就是讓大家看看Logo。
今天來寫從Logo頁面跳到Main頁面吧!
首先我們要建立第二個Activity
右鍵選取Activity的資料夾,會跳出下拉式選單選New > Activity > Empty Activity
接下來就像之前建立專案時,建立Activity一樣,寫好名稱以及相對應的xml就好。
接下來將Logo.java的程式碼加上以下這段程式碼,「Act01_Logo.this」為現在所在的Activity,「Act02_Main.class」是接下來要跳轉到的Activity。
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent();
intent.setClass(Act01_Logo.this, Act02_Main.class);
startActivity(intent);
finish();
}
}, 1500); //延遲1.5秒
完成程式碼如下:
package eucaly.com.kichou;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class Act01_Logo extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act01_logo);
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent();
intent.setClass(Act01_Logo.this, Act02_Main.class);
startActivity(intent);
finish();
}
}, 1500); //延遲1.5秒
}
}
大功告成囉!
文章標籤
全站熱搜