简体   繁体   English

更改Android虚拟键盘上“完成”按钮的操作

[英]Change Action of 'Done' Button on Virtual Keyboard Android

All- I looked at other questions relating to this topic and found out that according to the android development website: "the action key performs a "done" operation, typically meaning the IME will be closed." 全部-我查看了与此主题相关的其他问题,并根据android开发网站发现:“操作键执行了“完成”操作,通常意味着IME将被关闭。” My question is how do I edit the action of the done button to make it so it calls one of my methods instead of closing the IME? 我的问题是如何编辑完成按钮的操作以使其完成,以便它调用我的方法之一而不是关闭IME? Thanks for your time. 谢谢你的时间。

Best possible way 最好的方法

Example for handling Enter key event 处理输入键事件的示例

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    txt = (EditText)findViewById(R.id.txt);
    txt.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) 
         {
           if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) 
           {
               Log.d(TAG, "enter_key_called");
           }
            return false;
        }
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM