1. 程式人生 > >This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_

This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_

異常資訊:

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.

當在activity中呼叫了setSupportActionBar(toolbar); 

同時,AndroidManifest.xml 對應的Activity標籤的android:theme為

android:theme="@style/AppTheme" >

就會報這個異常。

解決方法:

在style.xml中加入:

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

在Manifest.xml中,修改theme:

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