我正在为双屏创建一个Android应用程序,其中包含2个活动启动画面和主页,其中主页活动启动模式声明为singleTask,如下所述:
<activity
android:name=".activity.SplashActivity"
android:theme="@style/FullScreen" />
<activity
android:name=".activity.HomeScreenActivity"
android:launchMode="singleTask"
android:theme="@style/DisableToolbar">
<style name="FullScreen" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:toolbarStyle">@android:color/transparent</item>
</style>
<style name="DisableToolbar" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:toolbarStyle">@android:color/transparent</item>
</style>
启动画面仅播放10秒的视频,并带有一些过渡动画进入家庭活动,当我们在单个屏幕中启动该过渡画面时效果很好,但是具有相同应用的2种不同风格并在两个应用中同时启动一次显示视频时在屏幕上和在调用家庭活动时都可以很好地播放,我可以在过渡期间或调用家庭活动之前看到一些android默认启动器作为背景,如何摆脱这种背景。我尝试了以下方法来解决此问题:
以下是启动活动的代码段:
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_activity);
mSurfaceView = findViewById(R.id.splashView);
}
@Override
protected void onStart() {
super.onStart();
setSplashVideo();
}
private void setSplashVideo() {
mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
mSurfaceHolder = surfaceHolder;
Uri videoUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.lr_oval_startup);
if (videoUri != null) {
mMediaPlayer = MediaPlayer.create(SplashActivity.this,
videoUri, mSurfaceHolder);
mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
mMediaPlayer.start();
}
});
mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
jump();
}
});
}
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
}
});
}
private void jump() {
if (isFinishing())
return;
startActivity(new Intent(SplashActivity.this, HomeScreenActivity.class));
finish();
overridePendingTransition(R.anim.overlay_in,0);
}
@Override
protected void onStop() {
super.onStop();
if (mMediaPlayer != null) {
mMediaPlayer.release();
mMediaPlayer = null;
}
}
我正在为双屏创建一个Android应用程序,其中包含2个活动启动画面和首页,其中首页活动启动模式声明为singleTask,如下所述:
将主题设为全屏,即针对HomeActivity解决了该问题。