I'm trying to set toolbar in activity. And after i used setSupportActionBar()
i had IllegalStateException
with stack trace
Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:197)
at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:126)
at com.fonum.screen.main.MainActivity.showActionBar(MainActivity.java:135)
I searched the solution, and found this and few answers more. I tried to use theme like they said, but it still gives me this error
Here is my style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="colorControlActivated">@color/switch_color</item>
<item name="android:colorForeground">@color/switch_color_transparent</item>
</style>
<style name="action_bar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
</style>
This is my android manifest:
<application
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme"
tools:replace="android:allowBackup">
And here is my main.xml:
<RelativeLayout
xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:background="@color/white">
<android.support.v7.widget.Toolbar
a:id="@+id/toolbar"
a:layout_width="match_parent"
a:layout_height="wrap_content"
a:elevation="4dp"
a:minHeight="@dimen/action_bar_height"
a:background="@color/primary"
app:theme="@style/action_bar"/>
<RelativeLayout
a:id="@+id/container"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:layout_below="@id/toolbar"/>
Any idea how to fix it?