android - windowBackground 未在设备上显示图像

标签 android image background window

我想要显示图像作为 Activity 背景。我想显示可绘制文件夹中的图像(river_background)。

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

背景图像瞬间显示。但显示控件后,背景变黑。感谢任何帮助

样式.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>

最佳答案

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

关于android - windowBackground 未在设备上显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47791625/

相关文章:

html - 背景图片会影响网站加载速度吗

php - 背景切换器?

android - 选择 Android 库的构建变体的 Gradle 脚本

android - 手动设置动态壁纸

android - Activity 生命周期/媒体在锁屏上恢复播放

PHP上传的图片被截断

Java 2D 图像调整大小忽略双三次/双线性插值渲染提示 (OS X + linux)

android - 为什么这个 android 取消警报不起作用?

html - 将图像链接到发布 URL 未指向

html - 将鼠标悬停在链接上时,如何让背景色覆盖它所在的整个框架?