Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the

来源:互联网 发布:php.ini cookie设置 编辑:程序博客网 时间:2024/05/20 13:14

 随手记录出现该bug的解决办法


Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not requestWindow.FEATURE_SUPPORT_ACTION_BARand set windowActionBar to false in your theme to use a Toolbar instead.


今天新建了一个activity并在activity里面设置这句话


 setSupporActivity(toolbar);


然后就上面这个错误了。

分析可能是因为在application节点中引用了 @style/AppTheme样式,而这个样式自带actionbar

所以我们在activit里面 setSupporActivity(toolbar)就会报这个错误。



解决办法:

去掉代码中的setSupporActivity(toolbar);使用application 的样式

或者在清单文件中 activity节点下加入

<activity android:name=".activity.MainActivity"    android:theme="@style/AppTheme.NoActionBar"    />

<style name="AppTheme.NoActionBar">    <item name="windowActionBar">false</item>    <item name="windowNoTitle">true</item>    <item name="android:windowDrawsSystemBarBackgrounds">true</item>    <item name="android:statusBarColor">@android:color/transparent</item></style>


2 0
原创粉丝点击