app启动白屏解决方法

导读

app启动的时候,会有一个闪屏页,英文叫SplashActivity。当点击应用图标,闪屏页如果不经过特别处理,会出现一小刻的白屏。
出现这个问题的原因是因为从启动应用到Activity闪屏也的onResume方法执行 的时间会比较耗时。

解决方法

我们把闪屏页的背景和图标可以设置在style里。这个style又是和Activity注册在AndroidManifest里的。

上代码

1.logo.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
  <item>

    <shape android:shape="rectangle" >
      <solid android:color="#f45232" />
    </shape>
  </item>

  <item android:bottom="48dp">
    <bitmap
        android:gravity="center"
        android:src="@drawable/hello" />
  </item>
</layer-list

第一个item:设置背景色
第一个item:居中的图片可以直接展示出来

2.将其作为我们当前Activity的windowBackground

  <style
      name="Theme2"
      parent="AppTheme" >
    <item name="android:windowBackground">@drawable/logo</item>
  </style>

3.设置到Activity上:

  <activity
        android:name=".activity.WhiteScreenActivity2"
        android:theme="@style/Theme2">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>

源码参考我的github地址

参考文章

http://blog.csdn.net/lmj623565791/article/details/43752383

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容