mcerovski
mcerovski

Reputation: 43

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" />

Upvotes: 4

Views: 4146

Answers (3)

Wasim K. Memon
Wasim K. Memon

Reputation: 6067

You can customise theme activity wise with android:theme attribute in their <activity> elements. And if don't provide any theme it will use application wise theme for that activity.

Hope it will clear more.

Upvotes: 0

Prithviraj Prabhu
Prithviraj Prabhu

Reputation: 93

The application's theme will be universal to the entire app, that's pretty obvious. But android gives you the functionality to individually set themes for your activities. For example, in your app, your MainActivity does not have an ActionBar. But you can create new activities in your app which may have an ActionBar with Light, or Dark theme, or any custom theme of your choice.

I hope this answers your question.

Upvotes: 2

CommonsWare
CommonsWare

Reputation: 1006614

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.

Upvotes: 3

Related Questions