解决办法:给当前启动页添加一个有背景的style样式
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">@mipmap/splash</item>
<item name="android:statusBarColor" tools:ignore="NewApi">@color/white</item>
<item name="android:windowIsTranslucent">true</item>
</style>
注意,在清单文件中
<activity android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
//将window的背景图设置为空
getWindow().setBackgroundDrawable(null);
super.onCreate(savedInstanceState);
}
<style name="SplashTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDisablePreview">true</item>
</style>
/**
* Activity屏蔽物理返回按钮
*
* @param keyCode
* @param event
* @return
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
原文:http://blog.51cto.com/11359966/2321477