26

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);
    }
}
Can Poyrazoğlu
  • 29,145
  • 40
  • 152
  • 327

9 Answers9

64

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>
Mehmet K
  • 2,719
  • 1
  • 19
  • 34
  • 1
    Can you explain why the user's code didn't work as he expected? – LarsH Jun 12 '20 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 '21 at 10:28
14

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>
trinity420
  • 606
  • 7
  • 18
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.

tomaset22
  • 357
  • 1
  • 2
  • 12
3

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

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'
}
Denis
  • 56
  • 5
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

Community
  • 1
  • 1
IntelliJ Amiya
  • 70,230
  • 14
  • 154
  • 181
0

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>
Taras Okunev
  • 380
  • 5
  • 9
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

t.m.
  • 1,265
  • 11
  • 22