使用Action的错误:This Activity already has an action bar supplied by the window decor.

异常信息:

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.

问题原因:

1、在清单文件中使用的是style中的theme:如图:

2、在布局文件中使用actionbar是也添加了一个theme,如图:

结果:添加多个theme就会报如上错误。

解决办法:

方法一:

扫描二维码关注公众号,回复: 17319719 查看本文章

1、在style文件中添加下面代码:

<!--toolbar-->
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

2、修改清单文件中的theme为:

android:theme="@style/AppTheme.NoActionBar"

方法二:

直接修改style文件中的主题为:Theme.AppCompat.Light.NoActionBar

 

结束。。。

猜你喜欢

转载自blog.csdn.net/qq_26554909/article/details/114487677
今日推荐