顯示具有 開啟畫面 標籤的文章。 顯示所有文章
顯示具有 開啟畫面 標籤的文章。 顯示所有文章

2016年3月2日 星期三

Android Splash Screen 新開啟畫面

前篇開啟app啟動畫面
http://terryyamg.blogspot.tw/2014/06/android-splashscreen.html
另一種方法

1.在 res/drawable/新增launch_screen.xml 上方加入android:opacity="opaque" 中間放入logo圖片並置中

    
    
    
    
        
    


2.在 res/values/styles.xml 新增一個AppTheme.Launcher
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.Launcher">
        <item name="android:windowBackground">@drawable/launch_screen</item>
    </style>

</resources>

3.在AndroidManifest.xml加入 android:theme="@style/AppTheme.Launcher"


    
        
            
                

                
            
        
    



4.最後MainActivity.java
package com.terryyamg.launchscreenstest;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.AppTheme); //加入此行
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}


檔案下載:
https://github.com/terryyamg/LaunchScreensTest
參考來源:
https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd

2014年6月5日 星期四

Android Splash Screen 開啟畫面

每個app都有開啟畫面,讓app有時間可以啟動一些功能
準備一張圖檔放在res⇒drawable-hdpi資料夾裡
1.AndroidManifest.xml
android:name="Your_package.SplashScreen"⇒⇒⇒⇒Your_package 你的package="xxx.xxxx.xxxxxx"
android:screenOrientation="portrait"⇒⇒⇒⇒landscape-橫屏,portrait-豎屏
action android:name="android.intent.action.MAIN"⇒⇒⇒⇒啟動點
category android:name="android.intent.category.LAUNCHER"⇒⇒⇒⇒啟動圖示

 
        
            
                

                
            
        
2.activity_splash.xml
在res⇒layout建立activity_splash.xml檔案
android:src="@drawable/load"⇒⇒⇒⇒load為圖檔名稱

 
    

    
 

3.SplashScreen.java
在跟MainActivity.java檔案同一個位置建立SplashScreen.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
 
public class SplashScreen extends Activity {
 
    // Splash screen timer
    private static int SPLASH_TIME_OUT = 3000; //開啟畫面時間(3秒)
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
 
        new Handler().postDelayed(new Runnable() {
 
            /*
             * Showing splash screen with a timer. This will be useful when you
             * want to show case your app logo / company
             */
 
            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                Intent i = new Intent(SplashScreen.this, MainActivity.class); //MainActivity為主要檔案名稱
                startActivity(i);
 
                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);
    }
 
}
參考來源:http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/