android - 为什么Android 8.1看不到资源?

标签 android splash-screen android-8.1-oreo

我将手机更新到 android 8.1 并启动了我的应用程序。我注意到了一个奇怪的错误——“找不到资源”。在 android 7.1 中一切正常。我已经尝试清理和重建项目。我认为下面的代码应该足以找到错误。

SplashActivity 样式

<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

bakcground_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

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

    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher"/>
    </item>

</layer-list>

list

<activity
    android:name=".splash.SplashActivity"
    android:theme="@style/SplashTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:scheme="http"
            android:host="music.pl"
            android:pathPrefix="/music" />
    </intent-filter>
</activity>

错误

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.linkplayer.linkplayer/com.linkplayer.linkplayer.splash.SplashActivity}: android.content.res.Resources$NotFoundException: Drawable com.linkplayer.linkplayer:drawable/background_splash with resource ID #0x7f07005e

在此先感谢您的帮助。祝你有个愉快的夜晚。

最佳答案

错误在这部分 xml:

<item>
    <bitmap
        android:gravity="center"
        android:src="@mipmap/ic_launcher"/>
</item>

我不知道为什么 Android 8.0+ 看不到 mipmap。我不得不使用“drawable”目录中的文件:

<item>
    <bitmap
        android:gravity="center"
        android:src="@drawable/my_drawable"/>
</item>

希望对你有所帮助。

关于android - 为什么Android 8.1看不到资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53841115/

相关文章:

android - 我有一台三星(7.1.1)设备,我用它来制作应用程序。当我尝试直接在设备上运行应用程序时,它显示一条错误消息

android - 无法在原始类型 int 上调用 getjsonobject(int)

java - 如何在 Android 中连接到 MongoDB 数据库?

android - 谷歌地图未在 Android 中显示

ios - Launchscreen.storyboard 横向启动画面

javascript - 为什么 react-native-onboarding-swiper 不能在我的启动画面上工作?

android - 通知无法在 Android Oreo (API 26) 中显示

ionic-framework - ionic 闪屏和微调器

android - 由于 FirebaseInstanceIdReceiver 中的 Intent { act=com.google.android.c2dm.intent.RECEIVE 广播而导致 ANR

android - Oreo (8.1) 上的 toast 重叠问题