1、异常如下:
Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features: { windowActionBar: false, windowActionBarOverlay: false, android:windowIsFloating: false, windowActionModeOverlay: false, windowNoTitle: false }
在使用ToolBar时,我们需要把ActionBar关掉,因此我们通常会加如下代码:
<item name="windowActionBar">false</item>
但是再使用的时候却会抛出AppCompat does not support the current theme features的异常。
2、解决办法如下:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
没错,就是在下面添加一个NoTitle的代码即可。
再次运行即可正常
当然,这里使用的是style修改的,那么能不能通过在java代码中去掉标题而不报错呢?答案是肯定的!
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
以上代码需要注意:需要写在setContentView()之前。