无法通过 setActionBar 设置工具栏 (Android)
Cannot set toolbar via setActionBar (Android)
这是我的工具栏布局。
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
以及获取它的代码。
Toolbar toolbar;
toolbar=(Toolbar) findViewById( R.id.my_toolbar)
setActionBar(toolbar)
只需使用 setSupportActionBar (toolbar)
而不是 setActionBar(toolbar)
。
应该这样工作。
这是我的工具栏布局。
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
以及获取它的代码。
Toolbar toolbar;
toolbar=(Toolbar) findViewById( R.id.my_toolbar)
setActionBar(toolbar)
只需使用 setSupportActionBar (toolbar)
而不是 setActionBar(toolbar)
。
应该这样工作。