【问题标题】:AppCompat Toolbar not ShowingAppCompat 工具栏不显示
【发布时间】:2016-03-06 04:43:19
【问题描述】:

在主题中声明 .NoActionBar 以及将toolbar 放入布局后,我的toolbar 不显示。我最终得到的正是你在声明没有操作栏时所期望的——没有操作栏。这是布局:

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"/>

【问题讨论】:

  • 您需要提供 xml 的完整结构,而不仅仅是 sn-ps。 activity_home 的根视图组类型是什么?是LinearLayout 吗?这里最有可能造成麻烦的原因是app_bar_homenav_viewheight 属性设置为match_parent,因此其中一个匹配父级并将另一个推到屏幕外。
  • 我不太明白。声明 .NoActionBar 后,为什么希望显示工具栏?我总是这样做是为了删除我的工具栏

标签: android android-layout android-activity appbar


【解决方案1】:

在你的活动中,你必须初始化你的工具栏(如果你还没有这样做的话)

Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

【讨论】:

猜你喜欢
  • 2015-03-26
  • 1970-01-01
  • 2017-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多