【问题标题】:White background during app launch应用程序启动期间的白色背景
【发布时间】:2013-01-05 21:36:00
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: android background styles themes


    【解决方案1】:

    或者你可以使用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>
    

    【讨论】:

      【解决方案2】:
      <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>
      

      【讨论】:

        【解决方案3】:

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

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

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

        【讨论】:

        • 正是我想要的。
        • 如何添加自定义颜色代码而不是预定义值?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-11-21
        • 2020-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-08
        相关资源
        最近更新 更多