2016-12-06 30 views
0

我跟着this link 創建了一個SplashActivity,它在加載MainActivity時顯示一個小圖標。 Everythink運行良好,我可以成功實現該圖標。現在我正在嘗試更改SplashActivity的圖標,但問題是我的設備上應用程序中的圖標未更新。我在代碼中更改的其他內容都將更新成功,期望主題。Splash 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> 

我幾乎用盡了一切辦法來更新代碼(克麗n項目,重建項目,使緩存無效,重新啓動Android Studio,在設備上刪除應用程序等),但只是主題在設備上無法正常工作,一切正常。

有沒有人有解決方案如何顯示正確的主題?

編輯: 即使我刪除的主題仍然存在的mainfest文件主題..

編輯2: 我想通了,當前顯示的圖標是標準的ic_launcher圖標,它可居中在中間。所以window_background.xml完全被主題忽略,我仍然不知道爲什麼。我也嘗試設置不同的主題作爲AppTheme.LauncherTheme的父項,但它不會改變任何內容。如果我刪除了AppTheme.LauncherTheme,那麼SplashActivity是emtpy,並且ic_launcher圖標被刪除。

+0

AppTheme.LauncherTheme有一個叫做window_background.xml的drawable。那是正確的嗎? – DroidBender

+0

當然這是我的錯我會更新這個問題! – RyuZz

回答

0

AppTheme.LauncherTheme應該延伸其中的Theme.AppCompat主題。我建議這樣的解決方案:

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

我試圖添加一個父項,但不幸的是它不能解決問題。 – RyuZz