CollapsingToolbarLayout not collapsing when EditText get focused

倖福魔咒の 提交于 2019-12-03 05:05:57

I've resolved this by adding OnFocusChangeListener to EditText and if it has focus - just collapse view with setExpanded method:

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(final View v, boolean hasFocus) {
        if (hasFocus) {
           mAppBarLayout.setExpanded(false, true);
        }
    }
});

If you want your CollapsingToolbarLayout be collapsed every time when your other EditText's from your layout get focused, then you should set the same OnFocusChangeListener to each of them.

ʍѳђઽ૯ท

RecyclerView is a scrollable widget which means, these scrollable widgets won't work with eachother.(But, RecyclerView is a child from NestedScrollingChild)

Check this question for more explanation:

How to use RecyclerView inside NestedScrollView?

But, you can use it with custom LinearLayoutManager

https://stackoverflow.com/a/32736113/4409113


By the way,

You could use that RecyclerView inside the CoordinatorLayout and outside the NestedScrollView.

Hope that helps.

I think after all researches this is the best solution

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(final View v, boolean hasFocus) {
    if (hasFocus) {
        mAppBarLayout.setExpanded(false, true); // second one for animation
    }
}
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!