彩色背景上的透明 9 补丁

Transparent 9-patch over colored background

我正在尝试创建启动画面 activity,它使用 9 补丁图像,除了我的应用程序的徽标外,该图像是透明的。因此,我想将 window 的背景颜色设置为在我的徽标后面显示。但是,不管我怎么弄,背景好像都非要黑

我试过同时设置 backgroundcolorBackground:

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

但是当 windowBackground 也被设置时两者都不起作用。

如何设置启动画面的背景颜色 activity 以便正确填充 9 补丁图像中的透明度?

我测试了你的代码,我发现在你的风格中我可以指定android:windowBackground、android:background或android:colorBackground,但不能同时指定多个。

我成功地在 styles.xml 中使用背景颜色,然后在常规布局 XML 中指定图像,使用透明度 属性。

Styles.xml 示例:

<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 示例:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher"
    android:alpha="0.5"/>

我在应用部分的AndroidManifest.xml中设置了样式:

android:theme="@style/AppTheme"