"Android Development experience" This Activity already have an action bar supplied by the window decor

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.