Java – How do I make EditText stick to the top of the screen when scrolling down the View?

How do I make EditText stick to the top of the screen when scrolling down the View?… here is a solution to the problem.

How do I make EditText stick to the top of the screen when scrolling down the View?

I’ve used CoordinatorLayout and know how to keep TabLayout at the top of the page when it’s below the toolbar.

However, I’m now working on a new application that has the following screen in its fragment. So the toolbar remains fixed at the top, but I want to implement a scrolling effect to move the EditText from the center of the blue image area to the top of the page (below the toolbar of the activity).

This is the layout I want (taken from the Trucaller app):

1) When publishing:

screen 1

2) When scrolling:

screen 2

I’ve tried a variety of techniques using CoordinatorLayout and NestedScrollView, but my EditText (SearchBar) always scrolls up with the entire blue image area (AppBarLayout).

Thank you.

Solution

Thanks to StickyScrollViewItems library. You still need to achieve the effect of fading out when scrolling up and fading in when scrolling down.

Related Problems and Solutions