本文介绍了当我在小部件中移动光标时,EditText中无响应的软键盘持续了几秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I move the cursor in a EditText widget the soft keyboard is unresponsive for a couple of seconds.

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

I have cold booted the device, and tried a different keyboard but the problem remains in just one EditText widget. This problem does not happen on a tablet or in the emulator just on this Samsung Galaxy S7.

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

It also does not happen for the same EditText widget when I rotate the device to landscape, where the softkeyboard covers the screen with it's own attached edit window. Which suggests the problem is internal to the EditText widget but that's ridiculous.

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

Everywhere else in the app, the keyboard works fine, including in the EditText widgets inside an AlertDialg and a EditTextPreference.

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

I have no animations or timers, so nothing that I can see which could be blocking the UI thread, but like I said it only happens if I move the cursor inside the EditText widget.

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

I can't easily display the code here as it has a lot of sensitive functionality in the activity which would be impossible to obfuscate just for display on SO.

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

This is LogCat starting with me moving the cursor then repeatedly pressing the Done action to close the keyboard.

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,此后第一次按下 Done 操作将关闭键盘.尽管我不确定这是因为输入事件接收器已被释放,还是因为我等待了几秒钟才按下 Done 操作.

And this is LogCat when I move the cursor then wait for the Disposing input event receiver event, after which the first press of the Done action closes the keyboard. Though I'm not sure if that is because the input event receiver was disposed off, or because I waited a couple of seconds before pressing the Done action.

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

由于问题不在其他设备上或应用程序中的其他任何地方发生,因此我对在哪里查找问题感到困惑.

As the problem does not occur on other devices or anywhere else in the app, I'm confused as to where to look for the problem.

编辑

EditText小部件的布局.

The layout for the EditText widget.

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

更新现在,无需对代码进行任何更改,即使我打开EditText却什么也不做,仍然会出现问题.输入EditText字段后,我现在需要等待几秒钟才能单击Backspace键.

UPDATENow without any changes to the code, the problem is happening even if I open the EditText and do nothing at all. I am now having to wait a couple of seconds to click the backspace key after I enter the EditText field.

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

As always I am having to wait for dispatchDetachedFromWindow to be called before I can make any changes to the text or click the Done action button. And I can't call that method directly in some listener because it is part of ViewRootImpl.

我开始怀疑这是否是该手机的本地设备,而不是所有S7设备的本地设备.

I'm starting to wonder if this is something local to this phone, rather than all S7 devices.

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

UPDATEA device reset solved whatever issue was causing this to happen. So it was a local issue on the device, nothing code related.

推荐答案

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

I got the same problem as you. As you said, it just happens on Samsung device.

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

I set some texts in the Editview in the onCreate and the cursor initially appears at the start of the text when the layout is shown. Then if we move the cursor to the end of the text and type back button immediately, the keyboard will lose response for several seconds. While it is working if you type another button rather than back button.

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

The possible affected case is users want to delete the existing text, so they type the back button. This issue makes them feel they have to type the back button multiple times to start deleting the text.

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

The possible solution is setting the cursor at the end of the text when initializing the EditView, something like:

 mUsernameEditView.setSelection(username.length());

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

I understand it is not perfect, but have other ideas.

真正的原因是我在 AppTheme 中覆盖了 android:textSelectHandle android:textSelectHandleLeft android:textSelectHandleRight >如下所示:

The real reason is I override android:textSelectHandle, android:textSelectHandleLeft and android:textSelectHandleRight in the AppTheme like below:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:textSelectHandle">@android:color/black</item>
    <item name="android:textSelectHandleLeft">@android:color/black</item>
    <item name="android:textSelectHandleRight">@android:color/black</item>
</style>

在对上面的代码进行注释后,问题消失了,但是如何更改选择颜色?

The issue is gone after commenting on the code above, but how to change the selection color?

这篇关于当我在小部件中移动光标时,EditText中无响应的软键盘持续了几秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 01:33