Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 材质设计编辑文本:OnFocusChanged停止浮动提示正常工作_Android - Fatal编程技术网

Android 材质设计编辑文本:OnFocusChanged停止浮动提示正常工作

Android 材质设计编辑文本:OnFocusChanged停止浮动提示正常工作,android,Android,我有以下文本: <android.support.design.widget.TextInputLayout android:id="@+id/et_login_account_wrapper" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center"> <EditText andro

我有以下文本:

<android.support.design.widget.TextInputLayout
    android:id="@+id/et_login_account_wrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center">

    <EditText
        android:id="@+id/et_login_account_number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/et_login_account_number"
        android:inputType="textEmailAddress"/>
</android.support.design.widget.TextInputLayout>
上面的代码工作正常,但浮动提示会出现问题。选择EditText时,浮动文本不再向上浮动,离开EditText时,浮动文本也不再向下浮动。但是,当你开始打字时,它仍然会浮起

我猜原因是因为我覆盖了OnFocusChangedListener,因此通常的浮点动画不再播放,因为我没有在我的侦听器中指定它这样做

我不知道怎么修理


任何帮助都将不胜感激

为什么不使用addTextChangedListener进行验证?您将在用户键入时提供反馈,不会出现焦点问题。就性能而言,这不会是一个问题。@Azertii感谢您的想法。这是一种可能性,但我仍然想知道是否可以使用onFocusChanged。至少现在我有了一个备份计划。如果你真的想使用focus listener,我会尝试将它添加到TextInputLayout上,看看会发生什么。TextInputLayout当然会侦听EditText中的焦点更改,并且您正在覆盖侦听器。我希望它能转发给自己的听众,但这只是一个猜测。我尝试过,但没有成功。我想得越多,我就越喜欢你的第一个想法,我想我可能会同意。有解决方案吗?为什么不使用addTextChangedListener进行验证?您将在用户键入时提供反馈,不会出现焦点问题。就性能而言,这不会是一个问题。@Azertii感谢您的想法。这是一种可能性,但我仍然想知道是否可以使用onFocusChanged。至少现在我有了一个备份计划。如果你真的想使用focus listener,我会尝试将它添加到TextInputLayout上,看看会发生什么。TextInputLayout当然会侦听EditText中的焦点更改,并且您正在覆盖侦听器。我希望它能转发给自己的听众,但这只是一个猜测。我尝试过,但没有成功。我想得越多,我就越喜欢你的第一个想法,我想我可能会同意。有什么解决办法吗?
    et_account_number.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                if (InputValidator.validateEmail(et_account_number, et_account_number_wrapper, getApplicationContext()) == 1) {
                    im_account.setVisibility(View.VISIBLE);
                } else {
                    im_account.setVisibility(View.INVISIBLE);
                }
                et_account_number_wrapper.clearFocus();

            }
        }
    });