2017-07-31 128 views
0

所以我試圖讓閃屏工作,但我無法弄清楚什麼。即使它應該是不同的顏色幷包含文本,我仍會在啓動畫面中看到一個白色屏幕。這裏是我的清單文件:Android:啓動畫面沒有顯示

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.haas.ryan.bouncingball"> 

    <!-- Gives permission to create directories and files --> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.READ_E 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/bb_logo" 
     android:label="@string/app_name" 
     android:roundIcon="@mipmap/ic_launcher_round" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity 
      android:name=".splash.SplashActivity" 
      android:screenOrientation="userLandscape"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".bbsource.MainActivity" 
      android:screenOrientation="userLandscape"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN"/> 
       <category android:name="android.intent.category.LAUNCHER"/> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

這裏是我的2閃屏相關的類:

SplashActivity.java

package com.haas.ryan.bouncingball.splash; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.Window; 
import android.view.WindowManager; 

import com.haas.ryan.bouncingball.bbsource.MainActivity; 

public class SplashActivity extends Activity { 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(new SplashEnvironment(this, this)); 
    } 

    public void finish() { 
     startActivity(new Intent(this, MainActivity.class)); 
     super.finish(); 
    } 
} 

SplashEnvironment。 java

package com.haas.ryan.bouncingball.splash; 

import android.app.Activity; 
import android.content.Context; 
import android.graphics.Canvas; 
import android.graphics.Color; 
import android.graphics.Paint; 
import android.view.SurfaceHolder; 
import android.view.SurfaceView; 

/** 
* Created by Ryan on 7/31/2017. 
*/ 

public class SplashEnvironment extends SurfaceView implements SurfaceHolder.Callback { 
    private SplashActivity splashActivity; 

    public SplashEnvironment(Context context, SplashActivity splashActivity) { 
     super(context); 
     this.splashActivity = splashActivity; 
     getHolder().addCallback(this); 
    } 

    public void surfaceCreated(SurfaceHolder sh) { 
     try { 
      Thread.sleep(10000); 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 
     splashActivity.finish(); 
    } 
    public void surfaceDestroyed(SurfaceHolder sh) {} 
    public void surfaceChanged(SurfaceHolder sh, int format, int width, int height) {} 

    public void onDraw(Canvas canvas) { 
     draw(canvas); 
    } 

    public void draw(Canvas canvas) { 
     super.draw(canvas); 
     canvas.drawColor(Color.RED); 
     System.out.println("got here"); 
     Paint paint = new Paint(); 
     paint.setColor(Color.BLUE); 
     paint.setTextSize(40f * getResources().getDisplayMetrics().density); 
     canvas.drawText("SPLASH SCREEN", 100, 100, paint); 
    } 
} 

白色屏幕在持續時間後消失,並最終加載bbsource.MainActivity並繪製它應有的所有內容。

那麼,爲什麼當我清楚地告訴它畫其他東西時,我會得到一個白色的屏幕?

+0

你有兩個發射活動的人..讓'MainActivity'默認 –

+0

https://stackoverflow.com/questions/43042818/splash-screen-image-for-landscape-and -portrait-using-theme/43043419#43043419 – Elsunhoty

回答

2

試試這個

public class SplashActivity extends Activity { 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(new SplashEnvironment(this, this)); 
    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() { 
     startActivity(new Intent(SplashActivity.this, MainActivity.class)); 
     finish(); 
     // close this activity 
    } 
}, 3000);// time for spalsh screen 
} 
+0

是的,這工作。感謝您的幫助 – Ryan

+0

@Ryan請接受我的答案,這樣可以幫助其他人也 –

+1

我計劃,只需要等待4分鐘大聲笑 – Ryan