在主题中声明.NoActionBar之后,以及将工具栏放在布局中,我的工具栏不会显示.我最终得到的正是你在宣布没有动作栏时所期望的 – 没有动作栏.这是布局:
activity_home.xml:
- <include
- layout="@layout/app_bar_home"
- android:layout_width="match_parent"
- android:layout_height="match_parent"/>
- <android.support.design.widget.NavigationView
- android:id="@+id/nav_view"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_gravity="start"
- android:fitsSystemWindows="true"
- app:headerLayout="@layout/nav_header_home"
- app:menu="@menu/activity_home_drawer"/>
app_bar_home.xml
- <android.support.design.widget.AppBarLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:theme="@style/AppTheme.AppBarOverlay">
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="?attr/actionBarSize"
- android:background="?attr/colorPrimary"
- app:popupTheme="@style/AppTheme.PopupOverlay"/>
- </android.support.design.widget.AppBarLayout>
- <include layout="@layout/content_home"/>
解决方法
在您的活动中,您必须初始化工具栏(如果您还没有这样做)
- Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);