Экран-заставка Android со стилем сбоя - PullRequest
0 голосов
/ 28 августа 2018

Дизайн заставки со стилем сбой. Ошибка происходит только Android API уровня 27 и выше. Структура кода выглядит следующим образом:

style.xml

<style name="SplashScreenTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name ="android:windowBackground"> @drawable/splash_screen_background</item>
</style>

splash_screen_background.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:opacity="opaque">
    <item
        android:drawable="@color/colorPrimary"/>

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

Manifest.xml

<application
    android:...
    android:theme="@style/AppTheme">

Исключение:

Exception java.lang.RuntimeException: Unable to start activity ComponentInfo{com....Views.SplashActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class ImageView
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2778)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2856)
android.app.ActivityThread.-wrap11 ()
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1589)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loop (Looper.java:164)
android.app.ActivityThread.main (ActivityThread.java:6494)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
arrow_drop_down
Caused by android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class ImageView
arrow_drop_down
Caused by android.view.InflateException: Binary XML file line #8: Error inflating class ImageView
arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: Drawable com...:mipmap/ic_launcher with resource ID #0x7f0e0000
arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/mipmap-anydpi-v26/ic_launcher.xml from drawable resource ID #0x7f0e0000
arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: Drawable com...:mipmap/ic_launcher with resource ID #0x7f0e0000
arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/mipmap-anydpi-v26/ic_launcher.xml from drawable resource ID #0x7f0e0000
arrow_drop_down
Caused by java.lang.Exception: Recursive reference in drawable

1 Ответ

0 голосов
/ 29 августа 2018

Чтобы применить тему к занятию, вы должны сделать это.

Допустим, я создал свою тему Splash следующим образом

<style name="SplashTheme" parent="Theme.MaterialComponents.NoActionBar">
    <item name="android:windowBackground">
        @drawable/splash
    </item>
</style>

Я создал splash.xml в Drawable

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />
<item>
    <bitmap
        android:gravity="center"
        android:src="@drawable/web_hi_res_512" />
</item>
</layer-list>

и затем вы используете это в манифесте, как это

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".SplashActivity"
        android:screenOrientation="portrait"
        android:theme="@style/SplashTheme"> // I have applied the theme to this activity
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

 ....
</application> 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...