I have an activity where I have set NavigationDrawer and works fine. This activity hosts a fragment where I have used:
setHasOptionsMenu(true);
To enable the menu. I have added a SearchView and override onCreateOptionsMenu()
:
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu, menu);
MenuItem searchItem = menu.findItem(R.id.search);
//Do some search stuff
}
And everything works fine. This the layout file of my fragment:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Now I want to collapse the toolbar while I'm scrolling through the RecyclerView
. I know I can add an AppBarLayout
and inside it a Toolbar
in my layout file, but is the any possibility to achieve the same behaviour with the existing one in a ConstraintLayout?