2016年8月12日 星期五

Android: Create A Launch Screen

since: 2016/08/12
update: 2016/08/12

reference:
1. GiveMePasS's Android惡補筆記: 如何建立登入過程的畫面


A. 建立專案後, 再新增第二個 Activity:
     1. app > File > New > Activity > Empty Activity

     2. Configure Activity > Finish

-----------------------------------------------------------------------------------------------

B. Design the Interface:
    1. 點選 activity_launch.xml 檔案, 修改如下:(在此只改變背景色)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.yourDomain.LaunchActivity"
    android:background="@color/colorAccent">

</RelativeLayout>


-----------------------------------------------------------------------------------------------

C. 開啟 LaunchActivity.java 修改如下:

package com.yourDomain.appName;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

//@add ------
import android.content.Intent;
import android.os.Handler;


public class LaunchActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launch);

        //@add ------
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(new Intent().setClass(LaunchActivity.this, MainActivity.class));
            }
        }, 3000); //delay 3 second, then
Intent to MainActivity
    }
}


-----------------------------------------------------------------------------------------------

D. 開啟 Androidmanifest.xml 修改如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="
com.yourDomain.appName">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/icon_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

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

        <activity android:name=".MainActivity">
        </activity>


    </application>

</manifest>


-----------------------------------------------------------------------------------------------

E. 結果:

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。