Error:
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.
Reason:
When the setSupportActionBar(toolbar);
Meanwhile, AndroidManifest.xml corresponds to the android:theme of the Activity tag as
android:theme="@style/AppTheme" >
Moreover, the parent in the style resource file is
parent="Theme.AppCompat.Light.DarkActionBar
It will report this exception.
Problem Analysis.
UsingTheme.AppCompat.Light
tells Android that you want the framework to provide an ActionBar for you. However, you are creating your own ActionBar (aToolbar
), so you are giving the framework mixed signals as to where you want the ActionBar to come from.
Solution.
- Add to the style configuration file
<item name="windowActionBar">false</item> <item name="windowNoTitle">true</item>
Or, change parent to
parent="Theme.AppCompat.Light.NoActionBar"
2. In the android:theme Refer to the modified topic in the style