Reputation: 768
I receive next exception :
Caused by: java.lang.IllegalStateException: 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.
I get exception when I call :
toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(toolbar);
MainActivity extends from AppCompatActivity. My app style :
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.NoActionBar"></style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:selectableItemBackground">@drawable/selectable_items_color</item>
<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>
<item name="android:textColorSecondary">@color/myTextPrimaryColor</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowFullscreen">true</item>
</style>
This is my toolbar :
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/ToolBarStyle"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="@drawable/action_bar"
android:minHeight="@dimen/toolbar_height">
And toolbar style :
<style name="ToolBarStyle" parent="">
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
Upvotes: 0
Views: 194
Reputation: 421
Try using <style name="AppBaseTheme" parent="Theme.AppCompat.NoActionBar"></style>
. As the exception reads "Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead." means your Theme is not being applied.
or
just add the line <item name="android:windowActionBar">false</item>
to your app style. Hope it helps
Cheers
Upvotes: 1
Reputation: 22212
Your Toolbar don't have an id
Add your id and try again
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/ToolBarStyle"
android:id=”@+id/toolbar_actionbar”
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="@drawable/action_bar"
android:minHeight="@dimen/toolbar_height">
Upvotes: 0