On a view I have a LinearLayout which I want to collapse when I click on the EditText below and then to expand when we unfocus.
<EditText
android:layout_width="1000dp"
android:layout_height="43dp"
android:layout_centerVertical="true"
android:textSize="14.4sp"
android:gravity="center_vertical"
android:hint="@string/hint_query"
android:layout_toEndOf="@+id/searchImage"
android:id="@+id/searchBoxText"
android:background="@null"
android:layout_marginStart="16dp"
android:inputType="text"
tools:ignore="Autofill" />
I have a onFocusChangeListener that I implemented thanks to Android-Annotations.
@FocusChange
void searchBoxText(EditText searchBoxText) {
Log.d("change focus", "focus has changed with " + searchBoxText.hasFocus());
if (!searchBoxText.hasFocus()) {
if(upperView != null)
upperView.setVisibility(View.VISIBLE);
} else {
if(upperView != null)
upperView.setVisibility(View.GONE);
}
}
And I got a touchListener on the parent which throws :
searchBoxText.clearFocus();
when we click out of the EditText.
The tablet I aim this code for support as the maximum API 24. My problem is that this code works perfectly in API 28 but not on API 24 where it throws the onFocusChange twice and I didn't find any reason as why it does it or any way to make it work.