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
Similar Posts:
- How to Solve setSupportActionBar() Method Error
- Actionbar expiration problem
- [Solved] Android Studio Warning: Failed to load AppCompat ActionBar with unknown error
- classes could not be found: – android.support.v7.i
- The Android studio preview interface reports an error render problem
- [Solved] error: resource style/AppTheme (aka com.example.myapplication:style/AppTheme
- [Solved] The activity must be exported or contain an intent-filter
- Can’t find it“ android:Theme.Holo.Light.DarkActionBar ” [How to Solove]
- [Solved] Android Studio Warning: Default Activity not found
- [Solved] Theme Error retrieving parent for item: No resource found that matche