How to override Soft keyboard keyPress event in android?

I need a listener's to detect user interaction on my activity which has a fragment attached to it, for which i have overriden diapatchTouchEvent() which is working fine for touch event and hard key events, but it does not work for soft keyboard keypress.

To intercept keyboard touch events i have tried onUserInteraction() , dispatchKeyEvents() , onKeyUp , onKeyDown but none of them is working for softkeyboard.

Is there any other way to intercept softkeyboard events in Android?

for above query i have gone through these links :

https://stackoverflow.com/a/25620981/3954050

Android SoftKeyboard onKeyDown/Up not detecting 'alternative' keys


If you want to intercept keyboard event like done, or search or enter etc, in your edit text add a imeOption like

<EditText
   ..../
  android:id="@+id/myEditText"
  android:imeOptions="actionSearch"/>

And add an EditorActionListener to that edit text.

myEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_SEARCH){
                //Do something
            }
链接地址: http://www.djcxy.com/p/18440.html

上一篇: 如何将键盘事件发送到Windows中的所有类型的应用程序?

下一篇: 如何覆盖Android中的软键盘按键事件?