在学习开源项目TooBar(带动画的ActionBar --------- ToolBar(兼容低版本))时,运行过程中出现了了一下错误:
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.
这个错误,注释走用了android.support.v7.widget包里的toolbar导致的;
这个Activity已经有了一个又window decor提供的action bar,不要请求Window.FEATURE_SUPPORT_ACTION_BAR并且在你的主体中设置windowActionBar为false用一个Toolbar来代替;
解决方法如下:
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> </resources>
把
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
改成
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">就可以了