2017-07-31 123 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