所以我试图让一个启动画面工作,但我无法解决问题。我在启动画面期间得到一个白色屏幕,即使它应该是不同的颜色并包含文本。这是我的清单文件:
的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个与Splash屏幕相关的课程:
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 :(得分:2)
试试这个
https://arxiv.org/e-print/1512.00567v3