当我在小部件中移动光标时,EditText中无响应的软键盘持续了几秒钟

问题描述 投票:0回答:1

当我在EditText小部件中移动光标时,软键盘几秒钟无响应。

我已冷启动设备,并尝试使用其他键盘,但问题仅存在于一个EditText小部件中。仅在此Samsung Galaxy S7上,在平板电脑或仿真器中不会发生此问题。

当我将设备旋转到横向时,对于同一EditText小部件,也不会发生这种情况,其中,软键盘以其自己的附加编辑窗口覆盖了屏幕。这表明问题是EditText小部件内部的问题,但这很荒谬。

在应用程序中的其他任何地方,键盘都可以正常工作,包括在AlertDialg和EditTextPreference内部的EditText小部件中。

我没有动画或计时器,所以看不到任何东西可能会阻塞UI线程,但是就像我说的那样,只有将光标移动到EditText小部件内时,它才会发生。

我无法在此处轻松显示代码,因为它在活动中具有很多敏感功能,不可能仅在SO上进行显示而混淆。

这是LogCat,从我开始移动光标,然后反复按Done操作以关闭键盘。

D/ViewRootImpl@3513940[MainActivity]: ViewPostIme pointer 0
D/ViewRootImpl@3513940[MainActivity]: ViewPostIme pointer 1
D/InputMethodManager: SSI - flag : 0 Pid : 9760 view : org.pep.dungle
D/ViewRootImpl@92caa69[PopupWindow:541b8a2]: setView = android.widget.PopupWindow$PopupDecorView{a26bcee VFE...C.. ......I. 0,0-0,0} TM=true MM=false
D/ViewRootImpl@92caa69[PopupWindow:541b8a2]: dispatchAttachedToWindow
V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
D/ViewRootImpl@92caa69[PopupWindow:541b8a2]: Relayout returned: old=[0,0][0,0] new=[378,969][1458,2889] result=0x7 surface={valid=true 543940485120} changed=true
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000,  [1080x1920]-format:1
D/OpenGLRenderer: eglCreateWindowSurface = 0x7ed5e10080
D/ViewRootImpl@92caa69[PopupWindow:541b8a2]: MSG_RESIZED_REPORT: frame=Rect(378, 969 - 1458, 2889) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
D/OpenGLRenderer: eglDestroySurface = 0x7ed5e10080
D/ViewRootImpl@92caa69[PopupWindow:541b8a2]: dispatchDetachedFromWindow
D/InputEventReceiver: channel '69e6cbf PopupWindow:541b8a2 (client)' ~ Disposing input event receiver.
D/InputEventReceiver: channel '69e6cbf PopupWindow:541b8a2 (client)' ~NativeInputEventReceiver.
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: setView = android.widget.PopupWindow$PopupDecorView{289c208 VFE...C.. ......I. 0,0-0,0} TM=true MM=false
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: dispatchAttachedToWindow
V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: Relayout returned: old=[0,0][0,0] new=[378,1035][1458,2955] result=0x7 surface={valid=true 543940485120} changed=true
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000,  [1080x1920]-format:1
D/OpenGLRenderer: eglCreateWindowSurface = 0x7ed5e10080
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: MSG_RESIZED_REPORT: frame=Rect(378, 1035 - 1458, 2955) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 0
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 1
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 0
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 1
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 0
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 1
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 0
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 1
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 0
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 1
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 0
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 1
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 0
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 1
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 0
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 1
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 0
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 1
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 0
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 1
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 0
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 1
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 0
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: ViewPostIme pointer 1
D/OpenGLRenderer: eglDestroySurface = 0x7ed5e10080
D/ViewRootImpl@9b68bab[PopupWindow:541b8a2]: dispatchDetachedFromWindow
D/InputEventReceiver: channel '71f96d5 PopupWindow:541b8a2 (client)' ~ Disposing input event receiver.
    channel '71f96d5 PopupWindow:541b8a2 (client)' ~NativeInputEventReceiver.
D/InputMethodManager: HSIFW - flag : 0 Pid : 9760
D/ViewRootImpl@3513940[MainActivity]: MSG_RESIZED: frame=Rect(0, 0 - 1080, 1920) ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1

这是LogCat,当我移动光标然后等待Disposition输入事件接收器事件时,此后第一次按Done操作将关闭键盘。尽管我不确定这是因为输入事件接收器已被释放,还是因为我等待了几秒钟才按下Done动作。

D/ViewRootImpl@3513940[MainActivity]: ViewPostIme pointer 0
D/ViewRootImpl@3513940[MainActivity]: ViewPostIme pointer 1
D/InputMethodManager: SSI - flag : 0 Pid : 9760 view : org.pep.dungle
D/ViewRootImpl@f9bed82[PopupWindow:efec7f7]: setView = android.widget.PopupWindow$PopupDecorView{7f4b4d0 VFE...C.. ......I. 0,0-0,0} TM=true MM=false
D/ViewRootImpl@f9bed82[PopupWindow:efec7f7]: dispatchAttachedToWindow
V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
D/ViewRootImpl@f9bed82[PopupWindow:efec7f7]: Relayout returned: old=[0,0][0,0] new=[378,969][1458,2889] result=0x7 surface={valid=true 543931449344} changed=true
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000,  [1080x1920]-format:1
D/OpenGLRenderer: eglCreateWindowSurface = 0x7ee0a40710
D/ViewRootImpl@f9bed82[PopupWindow:efec7f7]: MSG_RESIZED_REPORT: frame=Rect(378, 969 - 1458, 2889) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
D/OpenGLRenderer: eglDestroySurface = 0x7ee0a40710
D/ViewRootImpl@f9bed82[PopupWindow:efec7f7]: dispatchDetachedFromWindow
D/InputEventReceiver: channel '78a5217 PopupWindow:efec7f7 (client)' ~ Disposing input event receiver.
    channel '78a5217 PopupWindow:efec7f7 (client)' ~NativeInputEventReceiver.
D/ViewRootImpl@ca42c85[PopupWindow:efec7f7]: setView = android.widget.PopupWindow$PopupDecorView{b55aada VFE...C.. ......I. 0,0-0,0} TM=true MM=false
D/ViewRootImpl@ca42c85[PopupWindow:efec7f7]: dispatchAttachedToWindow
V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
D/ViewRootImpl@ca42c85[PopupWindow:efec7f7]: Relayout returned: old=[0,0][0,0] new=[378,1035][1458,2955] result=0x7 surface={valid=true 543931449344} changed=true
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000,  [1080x1920]-format:1
D/OpenGLRenderer: eglCreateWindowSurface = 0x7ed5fbc180
D/ViewRootImpl@ca42c85[PopupWindow:efec7f7]: MSG_RESIZED_REPORT: frame=Rect(378, 1035 - 1458, 2955) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
D/OpenGLRenderer: eglDestroySurface = 0x7ed5fbc180
D/ViewRootImpl@ca42c85[PopupWindow:efec7f7]: dispatchDetachedFromWindow
D/InputEventReceiver: channel '18797ed PopupWindow:efec7f7 (client)' ~ Disposing input event receiver.
    channel '18797ed PopupWindow:efec7f7 (client)' ~NativeInputEventReceiver.
D/InputMethodManager: HSIFW - flag : 0 Pid : 9760
D/ViewRootImpl@3513940[MainActivity]: MSG_RESIZED: frame=Rect(0, 0 - 1080, 1920) ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1

由于该问题不会在其他设备或应用程序中的其他任何地方发生,所以我在哪里寻找问题感到困惑。

编辑

EditText小部件的布局。

<EditText
    android:id="@+id/editText"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:background="@android:color/transparent"
    android:hint="@string/hint"
    android:imeOptions="actionDone"
    android:inputType="text"
    android:singleLine="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/bottom_guideline" />

处理片段中的代码。

    EditText editText = view.findViewById(R.id.editText);

    editText.setOnEditorActionListener((textView, actionId, event) ->
                                           {
                                               boolean handled = false;

                                               if (actionId == EditorInfo.IME_ACTION_DONE)
                                               {
                                                   // Save value.
                                                   valueOfEditText = textView.getText().toString();

                                                   // Shutdown the keyboard.
                                                   InputMethodManager imm = (InputMethodManager) textView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                                                   //noinspection ConstantConditions
                                                   imm.hideSoftInputFromWindow(textView.getWindowToken(), 0);

                                                   // Signal that we handled the input so any other listeners higher up will ignore it.
                                                   handled = true;
                                               }

                                               return handled;
                                           });

UPDATE现在,无需对代码进行任何更改,即使我打开EditText却不执行任何操作,问题仍然存在。在输入EditText字段后,我现在需要等待几秒钟才能单击Backspace键。

一如既往,我必须等到dispatchDetachedFromWindow被调用,然后才能对文本进行任何更改或单击“完成”操作按钮。而且我无法在某些侦听器中直接调用该方法,因为它是ViewRootImpl的一部分。

我开始怀疑这是否是此电话的本地设备,而不是所有S7设备的本地设备。

UPDATE重置设备可以解决导致此问题的任何问题。因此,这是设备上的本地问题,与代码无关。

android android-edittext android-softkeyboard
1个回答
0
投票

我遇到了与您相同的问题。如您所说,这只是在三星设备上发生的。

我在onCreateEditview中设置了一些文本,并且在显示布局时,光标最初出现在文本的开头。然后,如果将光标移到文本的末尾并立即键入back按钮,键盘将失去响应几秒钟。在工作时,如果键入另一个按钮而不是back按钮。

可能受影响的情况是用户要删除现有文本,因此他们键入后退按钮。此问题使他们感到必须多次键入返回按钮才能开始删除文本。

可能的解决方案是在初始化EditView时将光标设置在文本的末尾,类似于:

 mUsernameEditView.setSelection(username.length());

我了解它并不完美,但还有其他想法。

© www.soinside.com 2019 - 2024. All rights reserved.