解決辦法:給當前啓動頁添加一個有背景的style樣式php
<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>
注意,在清單文件中android
<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); }