全国免费服务热线:

18982081108
✕

成都弹性云服务器,成都高防云服务器,互联网数据服务,成都祈钰瑶

Android分享笔记(2)APP启动时闪屏

出处: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(白色或黑色);

是这样解决的:

  1. 首先 去掉图片设为背景,即空白layout;

  2. 定义一个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启动闪屏问题;

转载请注明出处: