简体   繁体   English

如何更改自定义启动画面中的背景颜色?

[英]How to change the background color in a custom made splash screen?

In order to remove the default white splash screen I made a custom theme:为了删除默认的白色闪屏,我制作了一个自定义主题:

styles.xml样式文件

 <style name="AppTheme.SplashTheme">
        <item name="android:windowBackground">@drawable/splash_screen</item>
  </style>

splash_screen.xml飞溅屏幕.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">

<!--<item android:drawable="?colorPrimary" />-->
<item>
    <bitmap
        android:gravity="center"
        android:src="@drawable/wq_logo" />
</item>
</layer-list>

Everything works fine but I want to change the background color of it.一切正常,但我想更改它的背景颜色。 Its currently showing a purple color background.它当前显示紫色背景。 I want to make it white.我想让它变白。 In this app I'm using a Navigation drawer layout.在这个应用程序中,我使用了导航抽屉布局。

Change the splash_screen.xml like this像这样更改splash_screen.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
         android:opacity="opaque">

<item>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"      
       android:shape="rectangle">
      <solid android:color="@color/grey" />
    </shape>
</item>
<item>
    <bitmap
        android:gravity="center"
        android:src="@drawable/wq_logo" />
</item>

You can add another item to the layer-list .您可以将另一个item添加到layer-list You only have to change the background color to your preferred one.您只需将背景颜色更改为您喜欢的颜色。

For my part, this solution did not solve the problem.就我而言,此解决方案并没有解决问题。 To fix it I declare the background image of the splash screen like this: (dont use bitmap)为了修复它,我像这样声明启动画面的背景图像:(不要使用位图)

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

<item
    android:drawable="@drawable/ic_launcher"
    android:gravity="center" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM