Collapsingtoolbarlayout Not Collapsing When Edittext Get Focused
Solution 1:
I've resolved this by adding OnFocusChangeListener
to EditText
and if it has focus - just collapse view with setExpanded
method:
editText.setOnFocusChangeListener(newView.OnFocusChangeListener() {
@OverridepublicvoidonFocusChange(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.
Solution 2:
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.
Solution 3:
I think after all researches this is the best solution
editText.setOnFocusChangeListener(newView.OnFocusChangeListener() {
@OverridepublicvoidonFocusChange(final View v, boolean hasFocus) {
if (hasFocus) {
mAppBarLayout.setExpanded(false, true); // second one for animation
}
}
});
Post a Comment for "Collapsingtoolbarlayout Not Collapsing When Edittext Get Focused"