Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: CollapsingToolbarLayout and SearchView, text overlapping

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?

like image 783
Tomas Avatar asked Nov 10 '22 11:11

Tomas


1 Answers

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.

like image 63
Greg Ennis Avatar answered Nov 15 '22 13:11

Greg Ennis