• <legend id='bW8ut'><style id='bW8ut'><dir id='bW8ut'><q id='bW8ut'></q></dir></style></legend>
      <bdo id='bW8ut'></bdo><ul id='bW8ut'></ul>

    <tfoot id='bW8ut'></tfoot>

    1. <i id='bW8ut'><tr id='bW8ut'><dt id='bW8ut'><q id='bW8ut'><span id='bW8ut'><b id='bW8ut'><form id='bW8ut'><ins id='bW8ut'></ins><ul id='bW8ut'></ul><sub id='bW8ut'></sub></form><legend id='bW8ut'></legend><bdo id='bW8ut'><pre id='bW8ut'><center id='bW8ut'></center></pre></bdo></b><th id='bW8ut'></th></span></q></dt></tr></i><div id='bW8ut'><tfoot id='bW8ut'></tfoot><dl id='bW8ut'><fieldset id='bW8ut'></fieldset></dl></div>

      <small id='bW8ut'></small><noframes id='bW8ut'>

        Android:如何通过示例获取任何 KeyPress 事件?

        时间:2023-08-31
          <bdo id='7CA01'></bdo><ul id='7CA01'></ul>

            <legend id='7CA01'><style id='7CA01'><dir id='7CA01'><q id='7CA01'></q></dir></style></legend>
            1. <tfoot id='7CA01'></tfoot>

              <small id='7CA01'></small><noframes id='7CA01'>

              <i id='7CA01'><tr id='7CA01'><dt id='7CA01'><q id='7CA01'><span id='7CA01'><b id='7CA01'><form id='7CA01'><ins id='7CA01'></ins><ul id='7CA01'></ul><sub id='7CA01'></sub></form><legend id='7CA01'></legend><bdo id='7CA01'><pre id='7CA01'><center id='7CA01'></center></pre></bdo></b><th id='7CA01'></th></span></q></dt></tr></i><div id='7CA01'><tfoot id='7CA01'></tfoot><dl id='7CA01'><fieldset id='7CA01'></fieldset></dl></div>
                <tbody id='7CA01'></tbody>

                  本文介绍了Android:如何通过示例获取任何 KeyPress 事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在用户按下任意键时获取键值,并根据在 android 中按下的键执行操作.

                  i want to get the key value when user pressed any key and also perform action based on the key pressed in android.

                  例如如果用户按下A"键,那么我想得到那个值,比较,做点什么.

                  e.g. if user pressed 'A' key then i want to get that value,compare,do something.

                  推荐答案

                  这个问题的答案应该是双重的.它由生成密钥的方式决定.如果它是按下硬件键,那么下面描述的两种方法都是有效的.如果是按软键,则视实际情况而定.

                  Answer to this question should be twofold. It is determined by the way how the key was generated. If it was press on the hardware key, then both approaches described below are valid. If it was press on the software key, then it depends on actual context.

                  1.) 如果按键是通过长按菜单键获得的软键盘按下的结果:

                  1.) If key was result of the pressing on the soft keyboard that was obtained by long press on the Menu key:

                  您需要小心地重写以下函数:

                  You need to carefully override the following function:

                  @Override 
                  public boolean onKeyDown(int keyCode, KeyEvent event) {
                  
                      switch (keyCode) {
                          case KeyEvent.KEYCODE_A:
                          {
                              //your Action code
                              return true;
                          }
                      }
                      return super.onKeyDown(keyCode, event);
                  }
                  

                  2.) 如果您的活动包含 EditText,并且从中获得了软键盘,则第一种方法不起作用,因为 EditText 已经使用了键事件.您需要使用文本更改的侦听器:

                  2.) If your activity contains EditText, and softkeyboard was obtained from it, then first approach does not work because key event was already consumed by EditText. You need to use text changed Listener:

                  mMyEditText.addTextChangedListener(new TextWatcher()
                  {
                      public void afterTextChanged(Editable s) 
                      {
                      }
                      public void beforeTextChanged(CharSequence s, int start, int count, int after) 
                      {
                          /*This method is called to notify you that, within s, the count characters beginning at start are about to be replaced by new text with length after. It is an error to attempt to make changes to s from this callback.*/ 
                      }
                      public void onTextChanged(CharSequence s, int start, int before, int count) 
                      {
                      }
                  );
                  

                  这篇关于Android:如何通过示例获取任何 KeyPress 事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:jQuery 是否保留触摸事件属性? 下一篇:onTouch,onLongClick一起在android中

                  相关文章

                  最新文章

                  • <bdo id='PxxOI'></bdo><ul id='PxxOI'></ul>
                • <legend id='PxxOI'><style id='PxxOI'><dir id='PxxOI'><q id='PxxOI'></q></dir></style></legend>

                  <small id='PxxOI'></small><noframes id='PxxOI'>

                    <i id='PxxOI'><tr id='PxxOI'><dt id='PxxOI'><q id='PxxOI'><span id='PxxOI'><b id='PxxOI'><form id='PxxOI'><ins id='PxxOI'></ins><ul id='PxxOI'></ul><sub id='PxxOI'></sub></form><legend id='PxxOI'></legend><bdo id='PxxOI'><pre id='PxxOI'><center id='PxxOI'></center></pre></bdo></b><th id='PxxOI'></th></span></q></dt></tr></i><div id='PxxOI'><tfoot id='PxxOI'></tfoot><dl id='PxxOI'><fieldset id='PxxOI'></fieldset></dl></div>

                    1. <tfoot id='PxxOI'></tfoot>