2016-12-06 36 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