Search code examples
androidandroid-manifestandroid-theme

Android Manifest app:theme


I just started new android project with Navigation Drawer.Looking into manifest i found that there are two android:theme. One inside application tag and one inside activity. My question is how come i can have multiple themes inside one application, and witch one is being used by my application.

AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.matija.ttestzbrisi">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

styles.xml

<resources>

<!-- 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>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />


Solution

  • The android:theme in the <application> element sets the default theme for all of your activities. Individual activities can override this default by having their own android:theme attribute in their <activity> elements.

    how come i can have multiple themes inside one application

    Not all activities will have the same theme. For example, some might use an action bar, and others not. Or, most might be full-screen activities, but others might be themed to be more like dialogs, not taking up the full screen.