本文介绍了clearFocus on editText 在三星 Galaxy Tab A(Android API 24)上调用两次 onFocusChange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

在一个视图上,我有一个 LinearLayout,当我点击下面的 EditText 时我想折叠它,然后在我们失去焦点时展开.

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" />

由于 Android-Annotations,我实现了一个 onFocusChangeListener.

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);
    }
}

我在父对象上有一个 touchListener 抛出:

And I got a touchListener on the parent which throws :

searchBoxText.clearFocus();

当我们点击 EditText 时.

when we click out of the EditText.

我将此代码作为最大支持 API 24 的平板电脑.我的问题是,这段代码在 API 28 中运行良好,但在 API 24 上运行得很好,因为它两次抛出 o​​nFocusChange 并且我没有找到任何理由来说明为什么这样做或以任何方式使其工作.

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.

推荐答案

可以在xml中添加isFocusable和FocusableInTouchMode用于另一个视图

You can add isFocusable and FocusableInTouchMode in xml for another view

这篇关于clearFocus on editText 在三星 Galaxy Tab A(Android API 24)上调用两次 onFocusChange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:16