This Activity already has an action bar supplied by the window decor (FEATURE_ACTION_BAR)

匿名 (未验证) 提交于 2019-12-03 03:04:01

问题:

This Activity already has an 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

This is the error I got, I searched for solutions but I didn't find how to solve it. This is my code:

styles.xml

<!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">     <item name="colorPrimary">@color/myPrimaryColor</item>     <item name="colorPrimaryDark">@color/myPrimaryDarkColor</item>     <item name="colorAccent">@color/myAccentColor</item>      <item name="android:textColorPrimary">@color/myTextPrimaryColor</item> </style>  <style name="ActionBarPopupThemeOverlay" parent="Theme.AppCompat.Light.NoActionBar">     <item name="windowActionBar">false</item> </style>  <style name="Toolbartitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">     <item name="android:textColor">@android:color/white</item> </style>  <style name="ToolbarSubtitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle">     <item name="android:textColor">#56FFFFFF</item> </style> 

send_comment.xml(my activity layout)

SendComment.java

public class SendComment extends ActionBarActivity {     private Toolbar toolbar;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.send_comment);         toolbar = (Toolbar) findViewById(R.id.my_toolbar);         toolbar.setTitle("");         setSupportActionBar(toolbar);     } } 

What am I doing wrong?

回答1:

In your AppTheme style use,

Theme.AppCompat.Light.NoActionBar 

instead of

Theme.AppCompat.Light.DarkActionBar 

You are setting a theme that has an actionbar and then you are setting toolbar as an actionbar. That's why your are getting this error.

Use the theme that has no actionbar instead and it will fix the issue.



回答2:

Use style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar" and everywhere use the same Theme as this maintain flow of Context to Android as it do not get confused between two ActionBar.



回答3:

Define this style  <style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">             <!-- Customize your theme here. -->             <item name="textColorError">@color/design_textinput_error_color_light</item>             <item name="android:windowNoTitle">true</item>             <item name="android:windowActionBar">false</item>             <item name="android:actionMenuTextColor">@color/color_white</item>             <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>         </style>  Please use this in your androidmanifest.xml file.This will resolve your problem.  


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!