异常信息:
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);