如何在应用程序上修复白屏启动?

Ano*_*ous 103 android splash-screen app-startup

我有一个Android应用程序,在启动时显示白色屏幕2秒.我的其他应用程序不这样做,但这个应用程序.我还实现了一个启动画面,希望能解决这个问题.我应该增加闪屏的睡眠时间吗?谢谢.

小智 155

把它放在自定义样式中,它解决了所有问题.使用hacky半透明修复将使您的任务栏和导航栏半透明,使闪屏或主屏幕看起来像意大利面条.

<item name="android:windowDisablePreview">true</item>

  • Thx man,从很多麻烦中解脱出来.我最初很难获得设定点.它将是主题块:内联`<style name ="AppTheme"parent ="Theme.AppCompat.NoActionBar"> <item name ="android:windowDisablePreview"> true </ item>`应该是主要样式的入口点.XML (3认同)
  • 我认为这会导致应用程序启动延迟 (3认同)
  • 谢谢!将它放在res文件夹中的style.xml到样式标记名称="AppTheme"(或在清单中使用的主题) (2认同)
  • 这不是一个好的解决方案,实际上根本不是一个解决方案,只是使白屏透明,但仍然需要几秒钟来加载启动器屏幕,感觉就像一个有缺陷的应用程序 (2认同)

use*_*543 99

只需在AndroidManifest.xml文件中提及启动活动的透明主题即可.

喜欢:

<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>
Run Code Online (Sandbox Code Playgroud)

并用Activity类代替扩展该屏幕AppCompatActivity.

喜欢 :

public class SplashScreenActivity extends Activity{

  ----YOUR CODE GOES HERE----
}
Run Code Online (Sandbox Code Playgroud)

  • Pankaj - 是的,我了解到糟糕的用户界面体验是由于"预览"窗口...显然,Google的某个人认为白色预览窗口在默认情况下真的很棒.但是,在使用深色背景的应用程序中,这是一个非常糟糕的主意.解决方案是为您的应用程序创建自定义样式,并将"android:windowBackground"指定为您要使用的颜色.请参阅"完美预览窗口"部分http://cyrilmottier.com/2013/01/23/android-app-launching-made-gorgeous/ (16认同)
  • 但是使用`final ActionBar actionBar = getActionBar();`当主题是半透明时`将返回null (4认同)
  • @Hagai L它给我一个错误,如"java.lang.IllegalStateException:你需要在这个活动中使用Theme.AppCompat主题(或后代)." (2认同)

Abh*_*bhi 70

在此输入图像描述

像你管..最初他们显示图标屏幕而不是白色屏幕.并在2秒后显示主屏幕.

首先在res/drawable中创建一个XML drawable.

<?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>
Run Code Online (Sandbox Code Playgroud)

接下来,您将把它设置为主题中的splash活动的背景.导航到styles.xml文件并为您的splash活动添加新主题

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

    <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/background_splash</item>
    </style>

</resources>
Run Code Online (Sandbox Code Playgroud)

在新的SplashTheme中,将窗口背景属性设置为XML drawable.在AndroidManifest.xml中将其配置为splash活动的主题:

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

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

此链接提供您想要的内容.一步一步的程序. https://www.bignerdranch.com/blog/splash-screens-the-right-way/

更新:

这样layer-list可以更简单(它也接受中心徽标的矢量绘图,与<bitmap>标签不同):

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Background color -->
    <item android:drawable="@color/gray"/>

    <!-- Logo at the center of the screen -->
    <item
        android:drawable="@mipmap/ic_launcher"
        android:gravity="center"/>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

  • 这是最好的答案.原因是当使用上述解决方案时,应用程序的可视启动会有延迟. (6认同)

Tar*_*run 66

在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>
Run Code Online (Sandbox Code Playgroud)

并将其与您在AndroidManifest中的活动一起使用:

<activity android:name=".ActivitySplash" android:theme="@style/Theme.Transparent">
Run Code Online (Sandbox Code Playgroud)

  • 如果我可以多次投票,我会这样做. (3认同)

fll*_*llo 7

你应该阅读Cyril Mottier撰写的这篇精彩帖子:Android App发布变得华丽

您需要自定义Themein style.xml,并避免在onCreateActionBar.setIcon/setTitle/etc中自定义.

另请参阅Google的性能提示文档.

使用Trace ViewHierarchy Viewer查看显示视图的时间:Android上的Android性能优化/性能调整

使用AsyncTask显示的一些看法.


lui*_*sta 5

这是我在应用示例应用中的AppTheme:

<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>
Run Code Online (Sandbox Code Playgroud)

如您所见,我有默认颜色,然后我添加了android:windowIsTranslucent并将其设置为true.

据我所知,作为Android开发人员,这是您需要设置的唯一事项,以便在应用程序的开头隐藏白屏.