Problem Description: Inherited from Appcompatactivity, when using toolbar instead of Actionbar, an error occurred
Error message:
- 2.Caused By:java.lang.IllegalStateException:This Activity already has a 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.
Problem reason Description: An error occurred when replacing with toolbar because the activity already exists Actionbar
Solution: Try to get rid of Actionbar
Solution Solutions
- 1. Use theme to remove Actionbar. You can resolve this issue by removing the actionbar using Theme.AppCompat.Light.NoActionBar or the Theme.AppCompat.NoActionBar theme.
The code is as follows
<resources> <stylename="Apptheme"Parent="Apptheme.base"> </style> <stylename="Apptheme.base"Parent="Theme.AppCompat.NoActionBar"> <Item name="Colorprimary"> @color/accent_material_light</Item> <Item name="Colorprimarydark"> @color/accent_material_light</Item> <Item name="Android:windowbackground"> @color/dark</Item> </style></resources>
- 2. If the above scenario is not available, set the properties of the theme to resolve the issue.
Add the following code to the Styles.xml in all Values-xx folders in your project to remove the Actionbar
<item name = "Windowactionbar" > false </item > <item name =" Android: Windowactionbar " >false </item > <item name =" Android:windownotitle " >true </ item > <item name = "Windownotitle" > true </item ;
There is a detail to note, because these properties are different for the version, so if a property is not recognized under your app version, the deletion is preserved.
Reprint Please specify source: http://blog.csdn.net/zhaokaiqiang1992
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Android Development experience" This Activity already have an action bar supplied by the window decor