activity 跳轉(zhuǎn):
場景:在啟動(dòng)頁蜂嗽,啟動(dòng)splashActivity界面(無setContentView)的時(shí)候,如果直接在onCreate里進(jìn)行頁面跳轉(zhuǎn)邏輯(延遲不高),則會(huì)造成黑屏0.5s左右踱承。并且splashActivity只執(zhí)行onCreate和onDestroy。
splashActivity主題:
<style name="SplashTheme" parent="AppTheme">
// 背景圖片logo
<item name="android:windowBackground">@drawable/layout_list</item>
<item name="android:windowFullscreen">true</item>
<!-- <item name="android:windowIsTranslucent">true</item> --> <!-- 透明背景不要了 -->
</style>
可能導(dǎo)致跳轉(zhuǎn)時(shí)候短暫黑屏一段時(shí)間。
可以通過
getWindow().getDecorView().findViewById(android.R.id.content).post(this::turnActivity);
黑屏的原因是泣刹,window層還沒有繪制完成,就進(jìn)行了跳轉(zhuǎn)犀被。當(dāng)window層繪制完成椅您,就可以執(zhí)行post。利用這個(gè)原理可以解決寡键。