出处:http://www.egef111.sh.cn/archives/95
App在启动时,即在欢迎界面。老是出现白屏或黑屏,闪一下然后才出现欢迎界面。
我欢迎界面原先是这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/bg_welcome"
android:orientation="vertical">
</LinearLayout>
把图片直接设置为背景,由于Activity只能到onResume时,才能展示到前台。所以这样直接设置为背景是会出现闪屏的,其实也不是闪屏,而是Activity的Style(白色或黑色);
是这样解决的:
首先 去掉图片设为背景,即空白layout;
定义一个Style 扩展自AppTheme,并设定windowBackground为需要显示的背景图片
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#8CC24F</item>
<item name="colorPrimaryDark">#8CC24F</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="WelcomeTheme" parent="AppTheme">
<item name="android:windowBackground">@mipmap/bg_welcome</item>
</style>
3.在Activity配置中引用
<activity
android:name=".AtyWelcome"
android:theme="@style/WelcomeTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
到此已经解决了App启动闪屏问题;
转载请注明出处:
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。