Android: CollapsingToolbarLayout and SearchView, text overlapping

3.3k Views Asked by At

I have little problem with overlapping CollapsingToolbarLayout title with SearchView text. When is CollapsingToolbarLayout expanded, there is no problem:

enter image description here

But when is collapsed, the text is overlapped:

enter image description here

How to fix it?

3

There are 3 best solutions below

4
On BEST ANSWER

I tried the answer by Tomas, but it had a problem that as soon as the user scrolls, the appbar collapses again and the problem re-appears.

So I came up with another solution which is to make the collapsed title text transparent when the searchview is expanded. This works nicely and does not depend on or change the collapse/expand state of the appbar.

Simply this:

    if (searchViewExpanding) {
        collapsingToolbarLayout.setCollapsedTitleTextColor(Color.TRANSPARENT);
    } else {
        collapsingToolbarLayout.setCollapsedTitleTextColor(Color.WHITE);
    }

Of course, you'll need to handle setOnActionExpandListener of your search menu item to know when to call this.

2
On

The answer is now simple, expand CollapsingToolbarLayout when search button is clicked. Thanks to Tuấn Trần Anh and this code:

coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
appBarLayout = (AppBarLayout) findViewById(R.id.appbar);
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();

behavior.setTopAndBottomOffset(0);
behavior.onNestedPreScroll(coordinatorLayout, appBarLayout, null, 0, 1, new int[2]);

more information is in this thread.

3
On

EDIT

Still not solve it, they have soleved another realted problem. With changing the text. The trick now is using the ControllableAppLayout to know when the bar is collapsed or expanded so then you just set and empty title setTitle("")

You can find my implementation here https://gist.github.com/skimarxall/863585dcd7abde8f4153

Issue: https://code.google.com/p/android/issues/detail?id=178138