vesii
vesii

Reputation: 3128

How to use no bar and full screen themes in Android?

I have a main screen and another two screen A and B. I would like the main screen be without an action bar while A and B do have them. So In my AndroidManifest.xml file I wrote:

        <activity android:name=".MainActivity"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".A"
            android:label="A"
            android:parentActivityName=".MainActivity" />
        <activity
            android:name=".B"
            android:label="B"
            android:parentActivityName=".MainActivity" />

Now I want all of the screens be full. From previous topics I need to add:

Theme.AppCompat.Light.NoActionBar.FullScreen

But theme is already being occupied. How do I set to full screen and have no action bar in the main screen?

Upvotes: 0

Views: 361

Answers (2)

Md. Yamin Mollah
Md. Yamin Mollah

Reputation: 1791

To get AppTheme's property inherited your styles.xml should look like this:

<!-- This is your "AppTheme" with ActionBar -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/primaryColor</item>
    <item name="colorPrimaryDark">@color/primaryDarkColor</item>
</style>

<!-- This is your "FullScreen Style" with no duplicate property -->
<style name="AppTheme.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

Then your Manifest.xml should look like this:

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".A"
            android:label="A"
            android:parentActivityName=".MainActivity" />
        <activity
            android:name=".B"
            android:label="B"
            android:parentActivityName=".MainActivity" />
    </application>

Upvotes: 0

Daniyal Nasir
Daniyal Nasir

Reputation: 148

Add this in the style file.

<style name="fullScreenTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="colorPrimary">@color/action_bar_color</item>
    <item name="colorPrimaryDark">@color/header_blue</item>
    <item name="colorAccent">@color/action_bar_color</item>
    <item name="android:fontFamily">@font/roboto_regular</item>
 </style>

use the below link either in application tag or activity tag.

 android:theme="@style/AppThemeActionBar"

Upvotes: 2

Related Questions