Android 向上滚动时,折叠工具栏中的SearchView将隐藏

Android 向上滚动时,折叠工具栏中的SearchView将隐藏,android,android-layout,searchview,android-coordinatorlayout,android-collapsingtoolbarlayout,Android,Android Layout,Searchview,Android Coordinatorlayout,Android Collapsingtoolbarlayout,我在MainActivity中有一个正在折叠的工具栏,在工具栏中有一个SearchView。单击searchview图标时,工具栏中的searchview将折叠。当工具栏折叠时,它可以正常工作。但如果我单击搜索图标并向上滚动,折叠的searchview将隐藏。我希望折叠的searchview在向上滚动时可见。我在跟踪 此链接 这是折叠工具栏折叠时的屏幕 现在,如果我点击搜索图标,屏幕如下所示 到目前为止,searchview运行良好。现在,如果我向上滚动屏幕,屏幕如下所示 现在,如果我单击

我在MainActivity中有一个正在折叠的工具栏,在工具栏中有一个SearchView。单击searchview图标时,工具栏中的searchview将折叠。当工具栏折叠时,它可以正常工作。但如果我单击搜索图标并向上滚动,折叠的searchview将隐藏。我希望折叠的searchview在向上滚动时可见。我在跟踪 此链接

这是折叠工具栏折叠时的屏幕

现在,如果我点击搜索图标,屏幕如下所示

到目前为止,searchview运行良好。现在,如果我向上滚动屏幕,屏幕如下所示

现在,如果我单击搜索图标,searchview会被折叠,但会被隐藏。因此,我希望在工具栏中折叠searchview,即使折叠工具栏未折叠。 这是当工具栏未折叠且单击搜索图标时我想要的屏幕截图

这是我的activity_main.xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleTextAppearance="@android:color/transparent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <com.daimajia.slider.library.SliderLayout
                android:id="@+id/slider"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                />

        </RelativeLayout>
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin" />
        <com.miguelcatalan.materialsearchview.MaterialSearchView
            android:id="@+id/search_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </android.support.design.widget.CollapsingToolbarLayout>
    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        app:tabIndicatorColor="@color/pink"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</android.support.design.widget.AppBarLayout>



<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:layout_margin="16dp"
    android:src="@drawable/ic_launcher_white"
    android:layout_gravity="end|bottom"
    app:rippleColor="@android:color/white"
    app:backgroundTint="@color/primary"
    app:elevation="10dp"
    />

我用
edittext
textchangedlistener

xml中

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorTransparent"
    android:fitsSystemWindows="true">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:background="@color/colorBlack_50"
        android:theme="@style/AppTheme.AppBarOverlay">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:fitsSystemWindows="true"
            android:gravity="bottom"
            app:contentScrim="@color/colorBlack_50"
            app:expandedTitleMargin="10dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            //some views

        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

你找到答案了吗?有人找到答案了吗?有人找到答案了吗???请帮我。。。Mstuck@hasan谢赫,你有解决办法吗???
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorTransparent"
    android:fitsSystemWindows="true">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:background="@color/colorBlack_50"
        android:theme="@style/AppTheme.AppBarOverlay">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:fitsSystemWindows="true"
            android:gravity="bottom"
            app:contentScrim="@color/colorBlack_50"
            app:expandedTitleMargin="10dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            //some views

        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>
editTextSearch.setVisibility(View.VISIBLE);
editTextSearch.addTextChangedListener(new TextWatcher() {
   @Override
   public void afterTextChanged(Editable s) {
       searchAudio(editTextSearch.getText().toString());
   }

   @Override
   public void beforeTextChanged(CharSequence cs, int s, int b, int c) {}

   @Override
   public void onTextChanged(CharSequence query, int s, int b, int c) {}
});