1. 程式人生 > >Android編程入門--簡單閃屏界面

Android編程入門--簡單閃屏界面

ash draw pla ont pack code welcom src title

Manifest

        <activity
            android:name=".ui.activity.WelcomeActivity"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER"
/> </intent-filter> </activity>

style

    <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <!-- 閃屏背景,可用圖片 -->
        <item name="android:windowBackground">@drawable/layer_splash</item>
        <item name="android:windowFullscreen"
>true</item> <item name="android:windowNoTitle">true</item> </style>

layer

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 背景顏色 -->
    <item android:drawable="@color/white"
/> <item> <!-- 圖片 --> <bitmap android:gravity="center" android:src="@mipmap/logo" /> </item> </layer-list>

activity

package com.zyp.energy.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;

import com.zyp.energy.R;

public class WelcomeActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        }, 500);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.fade, R.anim.hold);
    }
}

Android編程入門--簡單閃屏界面