19

This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead

This is the error I got, I searched for solutions but I didn't find how to solve it. This is my code:

styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/myPrimaryColor</item>
    <item name="colorPrimaryDark">@color/myPrimaryDarkColor</item>
    <item name="colorAccent">@color/myAccentColor</item>

    <item name="android:textColorPrimary">@color/myTextPrimaryColor</item>
</style>

<style name="ActionBarPopupThemeOverlay" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionBar">false</item>
</style>

<style name="Toolbartitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">
    <item name="android:textColor">@android:color/white</item>
</style>

<style name="ToolbarSubtitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle">
    <item name="android:textColor">#56FFFFFF</item>
</style>

send_comment.xml(my activity layout)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <android.support.v7.widget.Toolbar
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/my_toolbar"
            android:layout_height="128dp"
            app:popupTheme="@style/ActionBarPopupThemeOverlay"
            android:layout_width="match_parent"
            android:background="?attr/colorPrimary"
            android:paddingLeft="72dp"
            android:paddingBottom="16dp"
            android:gravity="bottom"
            app:titleTextAppearance="@style/Toolbartitle"
            app:subtitleTextAppearance="@style/ToolbarSubtitle"
            app:theme="@style/ThemeOverlay.AppCompat.Light"
            android:title="תגובה"
            />
</RelativeLayout>

SendComment.java

public class SendComment extends ActionBarActivity {
    private Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.send_comment);
        toolbar = (Toolbar) findViewById(R.id.my_toolbar);
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
    }
}

What am I doing wrong?

Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
Haim127
  • 585
  • 2
  • 8
  • 29
  • possible duplicate of [This Activity already has an action bar supplied by the window decor](http://stackoverflow.com/questions/26515058/this-activity-already-has-an-action-bar-supplied-by-the-window-decor) – Sufiyan Ghori Jan 05 '15 at 17:43
  • 1
    You say you searched for solutions, but the top hit is the duplicate suggestion posted above. Is it not exactly the same issue? – keyser Jan 05 '15 at 17:49
  • But I searched and found it, look that I add it to the style of the toolbar.If I will add it to the AppTheme, the app will crash bacause it is not the only activity, and the others using this actionbar.so why down me points if I tried already what you saying now? – Haim127 Jan 05 '15 at 18:16

3 Answers3

75

In your AppTheme style use,

Theme.AppCompat.Light.NoActionBar

instead of

Theme.AppCompat.Light.DarkActionBar

You are setting a theme that has an actionbar and then you are setting toolbar as an actionbar. That's why your are getting this error.

Use the theme that has no actionbar instead and it will fix the issue.

Hirak Chhatbar
  • 3,159
  • 1
  • 27
  • 36
  • But I am using the AppTheme for others activity's and when I changing it, the other activity's crash :/ – Haim127 Jan 05 '15 at 18:20
  • 3
    then apply theme to individual activity's in your manifest xml.... Create a separate style with parent as Theme.AppCompat.NoActionBar and use this for the activity where you need toolbar – Hirak Chhatbar Jan 05 '15 at 18:25
  • 3
    OK, I added the line `android:theme="@style/ActionBarPopupThemeOverlay"` to the specific activity and it's working.Thanks for helping – Haim127 Jan 05 '15 at 18:53
  • glad i could help.. happy programming :) – Hirak Chhatbar Jan 05 '15 at 18:55
  • I experienced the same problem now and made all the changes but still it did not work. I don't think Android Studios 1.1 updates changes to themes unless you invalidate but once I had invalidated, it worked fine. – Simon Apr 03 '15 at 20:55
  • Worked 100%. Thanks Hirak – Dirk De Winnaar Nov 17 '15 at 07:53
1

Use style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar" and everywhere use the same Theme as this maintain flow of Context to Android as it do not get confused between two ActionBar.

Yeahia2508
  • 7,526
  • 14
  • 42
  • 71
Ashwani
  • 127
  • 1
  • 4
0
Define this style 
<style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="textColorError">@color/design_textinput_error_color_light</item>
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowActionBar">false</item>
            <item name="android:actionMenuTextColor">@color/color_white</item>
            <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
        </style> 
Please use this in your androidmanifest.xml file.This will resolve your problem. 
Vinod Pattanshetti
  • 2,465
  • 3
  • 22
  • 36