I'm trying to create a splash activity that uses a 9-patch image that is transparent apart from my app's logo. Consequently, I would like to set the background color of the window to show through behind my logo. However, no matter what I do, it seems that the background is insisting on being black.
I've tried setting both background
and colorBackground
:
<style name="Splash" parent="android:Theme">
<item name="android:windowBackground">@drawable/splash</item>
<item name="android:background">@android:color/white</item>
<!--
<item name="android:colorBackground">@android:color/white</item>
-->
<item name="android:windowNoTitle">true</item>
</style>
But neither works when windowBackground
is also set.
How can I set the background color of my splash activity so that transparency in my 9-patch image is filled in correctly?
I tested your code, and I found that in your style I can specify android:windowBackground, android:background, or android:colorBackground, but not more than one at the same time.
I was successful in using a color for the background in the styles.xml, and then specifing the image in the regular layout XML, using an alpha property for transparency.
Styles.xml example:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:colorBackground">@android:color/holo_blue_bright</item>
</style>
</resources>
layout.xml example:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:alpha="0.5"/>
I have the style set in the AndroidManifest.xml under the application section:
android:theme="@style/AppTheme"