1. 程式人生 > 其它 >Android app開發 如何新增啟動介面

Android app開發 如何新增啟動介面

開啟任意的一個app時,其中大部分都會顯示一個啟動介面,於我而言印象最深的就是微信的大地球了,啟動介面通常情況下展示出的都是自家的logo,但也有甚者則直接把廣告放到了上面。

在這裡為大家提供兩種不同的設定方式:
一種是兩個Activity實現,即需要一個啟動介面的Activity和一個啟動介面執行完後跳轉到的Activity

另一種則是由一個Ativity實現,但相對程式碼量也增加了一些。

下面則開始介紹兩種設定啟動畫面的方式:
第一種(兩個Activity):
啟動介面的Activity

public class SplashActivity extends Activity{

private static int SPLASH_DISPLAY_LENGHT= 2000; //延遲2秒

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getWindow().requestFeature(Window.FEATURE_NO_TITLE);//去掉標題
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent(SplashActivity.this, MyViewpager.class); //第二個引數即為執行完跳轉後的Activity
startActivity(intent);
SplashActivity.this.finish(); //關閉splashActivity,將其回收,否則按返回鍵會返回此介面
}
}, SPLASH_DISPLAY_LENGHT);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
啟動介面對應顯示的佈局檔案

<LinearLayout
android:id="@+id/splashScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_image"
android:layout_width="300dp"
android:layout_height="300dp"
android:src="@mipmap/icon"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:gravity="center"
android:textSize="24sp"
android:textColor="#2B2929"
android:layout_marginTop="20dp"/>

</LinearLayout>
————————————————
原文連結:https://blog.csdn.net/weixin_43802738/article/details/92813458

搜尋

複製