android – AppCompat工具栏没有显示

前端之家收集整理的这篇文章主要介绍了android – AppCompat工具栏没有显示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
主题中声明.NoActionBar之后,以及将工具栏放在布局中,我的工具栏不会显示.我最终得到的正是你在宣布没有动作栏时所期望的 – 没有动作栏.这是布局:

activity_home.xml:

  1. <include
  2. layout="@layout/app_bar_home"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"/>
  5.  
  6. <android.support.design.widget.NavigationView
  7. android:id="@+id/nav_view"
  8. android:layout_width="wrap_content"
  9. android:layout_height="match_parent"
  10. android:layout_gravity="start"
  11. android:fitsSystemWindows="true"
  12. app:headerLayout="@layout/nav_header_home"
  13. app:menu="@menu/activity_home_drawer"/>

app_bar_home.xml

  1. <android.support.design.widget.AppBarLayout
  2. android:layout_width="match_parent"
  3. android:layout_height="wrap_content"
  4. android:theme="@style/AppTheme.AppBarOverlay">
  5.  
  6. <android.support.v7.widget.Toolbar
  7. android:id="@+id/toolbar"
  8. android:layout_width="match_parent"
  9. android:layout_height="?attr/actionBarSize"
  10. android:background="?attr/colorPrimary"
  11. app:popupTheme="@style/AppTheme.PopupOverlay"/>
  12.  
  13. </android.support.design.widget.AppBarLayout>
  14.  
  15. <include layout="@layout/content_home"/>

解决方法

在您的活动中,您必须初始化工具栏(如果您还没有这样做)
  1. Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
  2. setSupportActionBar(toolbar);

猜你在找的Android相关文章