The Android input method takes precedence over the view key.

Source: Internet
Author: User

The Android input method takes precedence over the view key.

An example is written for verification.

First, the input method

public class RemoteKeyboard extends InputMethodService  {  @Override public boolean onKeyDown(int keyCode, KeyEvent event) {        if (processKey(event, 0 != event.getRepeatCount()))            return true;        return super.onKeyDown(keyCode, event);    }    @Override public boolean onKeyUp(int keyCode, KeyEvent event) {        if (processKey(event, true))            return true;        return super.onKeyUp(keyCode, event);    }    private boolean processKey(KeyEvent event, boolean doIt) {         Log.e("======= " ," ============ processKey"); return false;}}

Second, app view

    final TextView et1 = (TextView)findViewById(R.id.editText1);et1.setOnKeyListener(new OnKeyListener() {        @Override        public boolean onKey(View v, int keyCode, KeyEvent event)        {        Log.e("====================","====OnKeyListener ");        }

Run program Printing

===================================: ============= ProcessKey

==================================== OnKeyListener

===================================: ============= ProcessKey

==================================== OnKeyListener

The first time should be KeyDown, and the second time should be KeyUp, indicating that the Android input method takes precedence over the view


I tried to rewrite system/usr/keychars/Generic. kcm.

Change B

Key B {
Base: 'B' fallback DPAD_CENTER
}

In a non-editable box, log is as follows:

05:18:09-23. 093 118 118 E ===============================: ============= processKey

05:18:09-23. 094 118 118 E ===============================: ============= processKey
05:18:09-23. 163 118 E =================================: ============= processKey
05:18:09-23. 163 118 E =================================: ============= processKey

It indicates that B is not accept, and then DPAD_CENTER is called.


In an editable box, B is accept, and the log is as follows:

===================================: ============= ProcessKey

===================================: ============= ProcessKey

Fallback is not called.


If the change is as follows:

Key B {
Base: fallback DPAD_CENTER
}

Four lines of log are required in an editable box, indicating that fallback is called.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.