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

来源:互联网 发布:微信发假金额红包软件 编辑:程序博客网 时间:2024/05/17 22:42

异常信息:
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.
at
android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar

@Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_scrolling);        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);        setSupportActionBar(toolbar);    }

当用了setSupportActionBar(toolbar);
同时android:theme=”@style/AppTheme”
就会抛出这个异常

解决办法:
AndroidManifest.xml 对应的Activity标签的android:theme改为含有NoActionBar

<activity android:theme="@style/AppTheme.NoActionBar">
android:theme="@style/Theme.AppCompat.Light.NoActionBar"android:theme="@style/Theme.AppCompat.NoActionBar"

注意:

以下这种形式是无效的

requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_scrolling);
0 0