Why is AppTheme.NoActionBar not working?
Asked Answered
B

9

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);
    }
}
Bursa answered 7/4, 2016 at 14:16 Comment(1)
add <item name="android:windowFullscreen">true</item> <item name="android:windowContentOverlay">@null</item>Rebeckarebeka
A
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>
Abstain answered 7/4, 2016 at 14:23 Comment(3)
Can you explain why the user's code didn't work as he expected?Disobedience
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.Abstain
omgggg thank you!!!!!!! I have been searching EVERYWHERESelfeducated
P
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>
Prothallus answered 5/4, 2017 at 20:57 Comment(0)
S
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.

Subsellium answered 7/4, 2016 at 14:24 Comment(1)
You saved me. Thanks.Hemipterous
H
3

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

Hazardous answered 7/4, 2016 at 14:22 Comment(0)
C
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'
}
Capwell answered 3/9, 2016 at 17:13 Comment(0)
T
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>
Telemark answered 23/4, 2017 at 9:38 Comment(0)
R
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

Rebeckarebeka answered 7/4, 2016 at 14:31 Comment(0)
A
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.

Aquileia answered 29/6, 2018 at 23:56 Comment(0)
A
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

Astrionics answered 7/11, 2019 at 13:23 Comment(1)
AppTheme.NoActionBar already declares AppTheme as the parent theme. The period does thatAbstain

© 2022 - 2024 — McMap. All rights reserved.