Splash Theme is not changing anymore

℡╲_俬逩灬. 提交于 2019-12-12 20:06:42

问题


I followed this link to create a SplashActivity which displayed a small icon while loading the MainActivity. Everythink worked fine and I could implement the icon successfully. Now I'm trying to change the icon for the SplashActivity but the Problem is that the icon in the application on my device is not updated. Everything else I change in the code will be updated successful expect the theme.

window_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/white"/>
<item>
    <bitmap
        android:src="@drawable/logo"
        android:gravity="center"/>
</item>
</layer-list>

styles.xml:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.LauncherTheme">
    <item name="android:windowBackground">@drawable/window_background</item>
</style>

AndroidManifest.xml:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity android:name=".SplashActivity"
        android:theme="@style/AppTheme.LauncherTheme"
        android:screenOrientation="sensorPortrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
...
</application>

I nearly tried everything to update the code (Clean Project, Rebuild Project, Invalidate Caches, restart Android Studio, Delete App on Device etc.) but just the theme is not working correctly on the device, everything else works.

Does anyone have a solution how to display the correct theme?

EDIT: Even if I remove the theme from the mainfest file the theme is still there..

EDIT 2: I figured out that the currently displayed icon is the standard ic_launcher icon which is centered in the middle. So the window_background.xml is completly ignored from the theme and I still don't know why. I also tried to set different themes as the parent for the AppTheme.LauncherTheme but it does not change anything. If I remove the AppTheme.LauncherTheme then the SplashActivity is emtpy and the ic_launcher icon is removed.


回答1:


AppTheme.LauncherTheme should extend one of the Theme.AppCompat themes. I suggest such solution:

<style name="AppTheme.LauncherTheme" parent="AppTheme">


来源:https://stackoverflow.com/questions/40998841/splash-theme-is-not-changing-anymore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!