30

I've created an Android app in Android Studio, and it has created these styles by default:

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

However, in an activity, I try to set this as a theme:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   ...
android:theme="@style/AppTheme.NoActionBar">

But when I run the app I'm getting the action bar:

enter image description here

Why am I getting an action bar? Am I doing something obviously wrong, or is Android Studio, Google's official IDE for it's own platform, trying to confuse/mislead its developers?

Here is my activity code, there's nothing in it that can cause the action bar to appear by itself:

public class WelcomeActivity extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        setContentView(R.layout.activity_welcome);
    }
}
1
  • 2
    add <item name="android:windowFullscreen">true</item> <item name="android:windowContentOverlay">@null</item> Apr 7, 2016 at 14:19

9 Answers 9

67

Try something like this:

<style name="AppTheme.NoActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
  </style>

and set this as the theme of your activity in the manifest, that is:

<activity
    ...
    android:theme="@style/AppTheme.NoActionBar">
</activity>
3
  • 1
    Can you explain why the user's code didn't work as he expected?
    – LarsH
    Jun 12, 2020 at 21:18
  • 1
    The theme AppTheme.NoActionBar and the elements used in it are activity styling. Applying it to a FrameLayout inside an Activity does not affect the parent activity styling.
    – Mehmet K
    Mar 22, 2021 at 10:28
  • omgggg thank you!!!!!!! I have been searching EVERYWHERE Apr 8, 2022 at 20:13
15

None of the other answers worked for me, but I found this solution:

Open values/styles.xml in Android Studio and change this:

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

to:

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

If you just let Android Studio auto generate the activity, look in activity_welcome. There is be android.support.design.widget.AppBarLayout and if you delete it, the ActionBar should be gone.

1
  • You saved me. Thanks.
    – wonsuc
    Apr 29, 2017 at 10:23
3

You might have an action bar in your layout, or set theme in AndroidManifest file

0
2

Once WelcomeActivity extends AppCompatActivity, try Theme.AppCompat.NoActionBar:

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
</style>

If not already done, include a version of appcompat library to your build.gradle:

dependencies {
    compile 'com.android.support:appcompat-v7:24.1.1'
}
1

you should use this theme in manifest.xml, same as:

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

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

And in styles.xml:

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

    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
0

You should add below

<item name="android:windowFullscreen">true</item>
<item name="windowActionBar">false</item>

You can use

 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

You can visit Full Screen Theme for AppCompat

0

Try checking the AndroidManifest.xml file. I found that the main theme was established for the app, but the theme I wanted to apply had to be added into the correct activity.

0

I had a similar problem with one of my activities which was not main. I had something like in the Mehmet K's answer as theme:

<style name="MyActivitysTheme">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

I just added the parent theme too:

<style name="MyActivitysTheme" parent="AppTheme">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

I guess this way it successfully override the main theme

1
  • AppTheme.NoActionBar already declares AppTheme as the parent theme. The period does that
    – Mehmet K
    Jul 15, 2020 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.