在app发射期间的白色背景

时间:2013-01-22 15:36:03

标签: android background styles themes

我想在我的应用程序启动的短时间内摆脱白色,但内容尚未显示。

我的主要活动是使用样式(来自Manifest),将@style/Theme.Sherlock.Light.DarkActionBar扩展为背景设置为<item name="android:background">@android:color/transparent</item>。我的布局中没有任何地方可以使用白色背景颜色,但在应用程序启动期间它会出现一小段时间。

在HierarchyViewer中,我导出了图层并检查了布局层次结构中确实没有白色实体。

在绘制布局之前,什么设置控制背景颜色?感谢。

3 个答案:

答案 0 :(得分:35)

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

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

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

答案 1 :(得分: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>

答案 2 :(得分:0)

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

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