Android 如何修复应用程序启动时的白色屏幕?

Android 如何修复应用程序启动时的白色屏幕?,android,splash-screen,app-startup,Android,Splash Screen,App Startup,我有一个android应用程序,启动时会显示2秒钟的白色屏幕。我的其他应用程序不能做到这一点,但这一个可以做到。我还实现了一个splashscreen,希望它能解决这个问题。我应该增加闪屏睡眠时间吗? 谢谢。你应该阅读Cyril Mottier的这篇伟大的文章: 您需要在style.xml中自定义主题,并避免在onCreate中自定义ActionBar.setIcon/setTitle/etc 另请参见Google提供的关于的文档 使用跟踪视图和层次结构查看器查看显示视图的时间: 使用Async

我有一个android应用程序,启动时会显示2秒钟的白色屏幕。我的其他应用程序不能做到这一点,但这一个可以做到。我还实现了一个splashscreen,希望它能解决这个问题。我应该增加闪屏睡眠时间吗?
谢谢。

你应该阅读Cyril Mottier的这篇伟大的文章:

您需要在style.xml中自定义
主题
,并避免在
onCreate
中自定义ActionBar.setIcon/setTitle/etc

另请参见Google提供的关于的文档

使用
跟踪视图
层次结构查看器
查看显示视图的时间:


使用
AsyncTask
显示一些视图。

只需在AndroidManifest.xml中将透明主题提到开始活动即可 文件

比如:


在style.xml中创建样式,如下所示:

<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowIsTranslucent">true</item>
</style>

真的
假的
真的
@空的
真的
并将其与AndroidManifest中的活动一起使用,如下所示:

<activity android:name=".ActivitySplash" android:theme="@style/Theme.Transparent">

将其设置为自定义样式,即可解决所有问题。使用哈克半透明修复将使你的任务栏和导航栏半透明,并使飞溅屏幕或主屏幕看起来像意大利面条


true

可以通过将清单中的主题设置为

<activity
        android:name=".MySplashActivityName"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" >
 <intent-filter>
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

之后,如果您得到
java.lang.IllegalStateException:此活动需要使用Theme.AppCompat主题(或子代)。
然后,您可能需要在MySplashActivity中扩展活动,而不是AppCompatActivity


希望有帮助

这是示例应用程序上的我的应用主题:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowIsTranslucent">true</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

真的
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
如您所见,我使用了默认颜色,然后添加了
android:windowIsTranslucent
,并将其设置为
true


据我所知,作为一名Android开发人员,这是唯一需要设置的东西,以便在应用程序启动时隐藏白色屏幕

两个属性都有效使用其中任何一个

    <style name="AppBaseThemeDark" parent="@style/Theme.AppCompat">
            <!--your other properties -->
            <!--<item name="android:windowDisablePreview">true</item>-->
            <item name="android:windowBackground">@null</item>
            <!--your other properties -->
    </style>

@空的
这是完美的

<activity
        android:name="first Activity Name"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" >
 <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

但是:


您是启动程序活动必须扩展活动,而不是默认情况下的AppCompatActivity

白色背景来自Apptheme。你可以显示一些有用的东西,比如你的应用程序徽标,而不是白色屏幕。可以使用自定义主题进行显示。在你的应用程序主题中,只需添加

android:windowBackground=""
属性。 属性值可以是图像、分层列表或任何颜色

就像你管的。。最初,它们显示图标屏幕而不是白色屏幕。2秒后显示主屏幕

首先在res/drawable中创建一个XML可绘制文件

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@color/gray"/>

    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher"/>
    </item>

</layer-list>

您应该禁用即时运行android studio设置

文件>设置>构建、执行、部署>即时运行取消选中此处显示的所有选项。

I encountered a similar problem and to overcome it, I implemented the code below in styles, i.e res->values->styles->resource tag 
<item name="android:windowDisablePreview">true</item>

Here is the whole code:

<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowDisablePreview">true</item>
</style>

注意:即时运行导致的白屏问题仅适用于调试版本,此问题不会出现在发布版本中。

以下是建议如何设计启动屏幕的链接。为了避免白色/黑色背景,我们需要定义一个带有飞溅背景的主题,并在清单文件中将该主题设置为飞溅

res/drawable文件夹中的splash_background.xml

<?xml version=”1.0" encoding=”utf-8"?>
 <layer-list xmlns:android=”http://schemas.android.com/apk/res/android">

 <item android:drawable=”@color/colorPrimary” />

 <item>
 <bitmap
 android:gravity=”center”
 android:src=”@mipmap/ic_launcher” />
 </item>

</layer-list>


在我的一个项目中,我也遇到了同样的问题。我通过在提供给初始屏幕的主题中添加以下参数来解决这个问题

<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
true
@空的
真的

你可以在我的书面文件中找到原因和解决办法。希望有帮助。

请尝试以下代码:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowIsTranslucent">true</item>
</style>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
真的
假的
真的
@空的
真的

这段代码适合我,可以在所有Android设备上使用。

它的解决方案非常简单

这个问题有三个基本原因

  • 您正在OnCreateView函数中执行繁重/长时间运行/复杂的任务
  • 如果您正在使用线程。然后线程睡眠时间可能非常长
  • 如果您正在使用任何第三方库。在应用程序启动时初始化,可能会导致此问题
  • 解决方案:

      Remove the Heavy Task from onCreateView() function and place it some where appropriate place.
    
      Reduce the Thread Sleep time.
    
      Remove the Third party library at app initialize at implement them with some good strategy.
    
    解决方案1:

      Remove the Heavy Task from onCreateView() function and place it some where appropriate place.
    
      Reduce the Thread Sleep time.
    
      Remove the Third party library at app initialize at implement them with some good strategy.
    
    解决方案2:

      Remove the Heavy Task from onCreateView() function and place it some where appropriate place.
    
      Reduce the Thread Sleep time.
    
      Remove the Third party library at app initialize at implement them with some good strategy.
    
    解决方案3:

      Remove the Heavy Task from onCreateView() function and place it some where appropriate place.
    
      Reduce the Thread Sleep time.
    
      Remove the Third party library at app initialize at implement them with some good strategy.
    
    在我的例子中,我使用的是导致这个问题的糖ORM


    共享以改进。

    白色背景是由于Android在应用程序加载内存时启动造成的,如果您只需在Splash主题下添加这两行代码,就可以避免

    <item name="android:windowDisablePreview">true</item>
    <item name="android:windowIsTranslucent">true</item>
    
    true
    真的
    
    这解决了问题:

    编辑styles.xml文件:
    将代码粘贴到下面:

    <resources>
    
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="android:windowFullscreen">true</item>
            <item name="android:windowContentOverlay">@null</item>
            <item name="android:windowIsTranslucent">true</item>
        </style>
    
    </resources>
    
    
    真的
    @空的
    真的
    

    不要忘记在AndroidManifest.xml文件中进行修改。(主题名称

    请注意此文件中活动的声明顺序。

    我遇到了类似的问题,为了克服它,我在样式中实现了下面的代码,即res->value->style->resource标记
    
    I encountered a similar problem and to overcome it, I implemented the code below in styles, i.e res->values->styles->resource tag 
    <item name="android:windowDisablePreview">true</item>
    
    Here is the whole code:
    
    <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowDisablePreview">true</item>
    </style>
    
    真的 以下是全部代码: 真的
    您正在启动的活动花费的时间太长,无法完成其
    onCreate
    部分。请尝试在该活动中使用“setContentView”,并检查延迟是否消失。对不起,我是一名新手,我没有java方面的经验,您能解释清楚吗?请给出一个“答案”,这样我就可以勾选:)你在项目中使用java还是c?希望这个链接能帮助你:请通过链接,但使用
    最终Ac