在协调器布局中添加工具栏标题,可以通过以下步骤实现:
CoordinatorLayout
作为根布局,并在其中添加一个AppBarLayout
和一个Toolbar
。<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:title="工具栏标题" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<!-- 添加其他内容 -->
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Toolbar
中设置app:title
属性为你想要显示的工具栏标题。CollapsingToolbarLayout
中设置app:layout_collapseMode="pin"
。这样,你就成功在协调器布局中添加了工具栏标题。根据具体需求,你可以在CoordinatorLayout
中添加其他内容,如内容布局、滚动视图等。
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云