windowBackground未在设备上显示图像

时间:2017-12-13 11:12:50

标签: android image background window

我想要一个展示图像作为活动的背景。我想从drawable文件夹中显示一个图像(river_background)。

我在styles.xml中使用android:windowBackground来显示图像,它在运行api 23的模拟器中工作。背景图像显示很好。但是当我在运行api 23的设备(Moto G3)上运行它时。背景图像没有显示。背景是黑色的。

背景图片显示瞬间。但是在显示控件后,背景变黑。任何帮助表示赞赏

styles.xml

<resources>
    <style name="AppTheme.Transparent" parent="AppTheme">
        <item name="android:windowBackground">@drawable/river_background</item>
        <item name="windowActionBarOverlay">true</item>
    </style>

    <style name="AppTheme.Transparent.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/river_background</item>
        <item name="windowActionBarOverlay">true</item>
    </style>
</resources>

V21 / styles.xml

<resources>

    <style name="AppTheme.Transparent" parent="AppTheme">
        <item name="android:windowBackground">@drawable/river_background</item>
        <item name="windowActionBarOverlay">true</item>
        <item name="android:windowTranslucentStatus">true</item>
    </style>

    <style name="AppTheme.Transparent.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/river_background</item>
        <item name="windowActionBarOverlay">true</item>
        <item name="android:windowTranslucentStatus">true</item>
    </style>

</resources>

1 个答案:

答案 0 :(得分:3)

确保所有文件夹上都有图片。即,Drawable-hdpi,Drawable-mdpi,Drawable-xdpi,Drawable-xxdpi和Drawable-xxxdpi。