应用启动时白色背景

12

我想在应用启动但内容未显示时,消除白色背景。

我的主要活动使用从清单中继承的样式(@style/Theme.Sherlock.Light.DarkActionBar),并将背景设置为<item name="android:background">@android:color/transparent</item>。在我的布局中没有使用白色背景颜色,但在应用程序启动期间会短暂出现。

在HierarchyViewer中,我导出了图层并检查了布局层次结构中是否真的没有白色纯色。

哪个设置控制布局绘制之前的背景颜色?谢谢。

3个回答

40

你的主题中还有一个背景属性-windowBackground,并且你通过从@style/Theme.Sherlock.Light.DarkActionBar继承样式将其隐式设置为白色(注意名称中的.Light.部分)。

您可以使用主题的深色版本或通过在样式定义中包含windowBackground来明确设置它:

<item name="android:windowBackground">@color/your_color</item>   

1
你如何添加自定义颜色代码而不是预定义值? - Deepak Terse

0

或者您可以使用drawable。我为我的启动屏幕创建了一个主题,如下所示:)

<style name="SceneTheme.Light.NoActionBar" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="SceneTheme.Light.NoActionBar.Transparent.StatusBar" parent="SceneTheme.Light.NoActionBar">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowBackground">@drawable/bg_splash</item>
</style>

0
<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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接