安卓:CollapsingToolbarLayout与搜索查看,文字重叠文字、CollapsingToolbarLayout

2023-09-06 14:53:17 作者:于人海间拥抱

我有个小问题与搜索查看文字重叠CollapsingToolbarLayout称号。当CollapsingToolbarLayout扩大,就没有问题:

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

但是,当处于折叠状态,文字重叠:

But when is collapsed, the text is overlapped:

如何解决?

推荐答案

我试图由Tomas答案,但它有,一旦用户滚动,该appbar再次崩溃问题,该问题再次出现。

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.

于是我想出了另一种解决方案是使倒塌标题文本透明的,当搜索查看扩展。这个工程很好,不依赖于或更改折叠/展开的appbar的状态。

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.

简单:

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

当然,你需要处理 setOnActionExpandListener 您的搜索菜单项的知道什么时候调用此。

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