【发布时间】:2020-03-23 18:55:43
【问题描述】:
我在折叠工具栏上创建搜索栏之类的东西时遇到了问题。
问题来了:
首先,我创建一个折叠工具栏
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="240dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="@android:color/transparent"
android:fitsSystemWindows="true">
...
</android.support.design.widget.CollapsingToolbarLayout>
在 CollapsingToolbarLayout 中,我添加了一些分层图像、后退按钮和标题。 它看起来像这样:
<!-- Background on Verified Store -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="240dp"
android:background="@drawable/verifiedkosong"
app:layout_collapseMode="parallax"
android:scaleType="centerCrop">
<!-- Back arrow -->
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/arrow_back_white"
android:layout_margin="16dp"
android:id="@+id/close" />
<!-- Activity title on center -->
<LinearLayout
android:gravity="center_horizontal|left"
android:layout_marginEnd="-23dp"
android:layout_marginTop="-15dp"
android:id="@+id/viewtext"
android:layout_below="@+id/close"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- Text image -->
<ImageView
android:layout_marginTop="20dp"
android:id="@+id/imgVerifIcon"
android:layout_width="match_parent"
android:layout_height="32dp"
android:src="@drawable/textshadow"
android:layout_gravity="bottom" />
</LinearLayout>
<!-- Layered image for background -->
<ImageView
android:layout_marginTop="110dp"
android:layout_width="match_parent"
android:layout_height="80dp"
android:src="@drawable/detail_verified"
android:layout_gravity="bottom"
android:layout_marginLeft="8dp"/>
</RelativeLayout>
然后,我添加了一个搜索栏。我让它作为一个按钮工作。如果它被点击,它将转到另一个活动(搜索活动以获取样本)
<RelativeLayout
android:layout_marginTop="185dp"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/backallborderradiusstore">
<!-- SearchBar LinearLayout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
My SearchBar is here
</LinearLayout>
</RelativeLayout>
之后,我添加了一个工具栏。我仍然不知道如何在此工具栏上添加我的搜索栏。这是我的工具栏:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="Verified Store"
app:layout_collapseMode="pin"/>
【问题讨论】: