Search code examples
androidandroid-theme

Two styles on two different Activities


I have a splash screen and other Activities.

The idea is that I want the splash screen to be full screen, and all the other Activities to have a title bar and an ActionBar, as usual.

I set 2 styles in the styles.xml file

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

<!-- Splash theme. -->
<style name="Splash" parent="@style/Theme.AppCompat.Light">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

Then in the manifest file I put

android:theme="@style/AppTheme"

After that, I'm lost: I tried to set the style &/or theme to use "Splash" for the splashScreen in xml code, but it didn't work

Setting the manifest style changes all the app Activities, and I want to change only one

Any help would be appreciated.


Solution

  • Change the activity theme, not the application theme.

    <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:fullBackupContent="false"
            android:label="@string/app_name"
            android:theme="@style/AppTheme"> <!-- Not here -->
    
        <activity 
            android:name=".SplashActivity"
            android:theme="@style/Splash" /> <!-- Change/add here -->
    

    But note: parent="Theme.AppCompat.Light.NoActionBar" is the one you want if you want no Toolbar