啓動圖啓動界面的簡單實現

一、Android App啓動圖啓動界面的簡單實現

 

1.activity實現

創建一個Splash activity

public class Splash extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState);
        //加載啓動界面
        setContentView(R.layout.activity_splash);
        Integer time = 2000;    //設置等待時間,單位爲毫秒
        Handler handler = new Handler();
        //當計時結束時,跳轉至主界面
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(new Intent(Splash.this, MainActivity.class));
                Splash.this.finish();
            }
        }, time);
    }

}

2.xml實現

對應一個xml,我直接把圖片作爲背景處理,這樣可以直接將圖片裁剪好,不用另外處理。

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/pika"
    >
</LinearLayout>

3.修改配置文件AndroidManifest中的代碼

去Androidmanife設置最先加載

        <activity android:name=".Splash"
                   android:theme="@style/FixSystemWindowTheme">    

去style裏去除titlebar實現全屏效果

<style name="FixSystemWindowTheme" parent="AppTheme">
    <item name="android:windowFullscreen">true</item>
    <item name="windowNoTitle">true</item>
    </style>

最後,效果圖

 

轉:https://www.jianshu.com/p/84fdde25a0f7

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章