Android KeyEvent和EditorInfo之间有什么区别?

Android KeyEvent和EditorInfo之间有什么区别?,android,android-edittext,autocompletetextview,Android,Android Edittext,Autocompletetextview,当我遇到KeyEvent和EditorInfo时,我正在学习textView.setOnEditorActionListener。这是我的密码: actv_search_activity.setOnEditorActionListener(object : TextView.OnEditorActionListener{ override fun onEditorAction(v: TextView?, actionId: Int, event: KeyEvent): B

当我遇到
KeyEvent
EditorInfo
时,我正在学习
textView.setOnEditorActionListener
。这是我的密码:

actv_search_activity.setOnEditorActionListener(object : TextView.OnEditorActionListener{
            override fun onEditorAction(v: TextView?, actionId: Int, event: KeyEvent): Boolean {
                if (actionId == EditorInfo.IME_ACTION_SEARCH){

                }
                return true
            }

        })
早些时候,我尝试使用
if(event!!.action==KeyEvent.KEYCODE\u SEARCH)
,从中我得到了一个NPE


那么,
KeyEvent
EditorInfo
之间有什么区别呢?

据我所知,KeyEvent是非常基本的, 用户在键盘上单击9->
KeyEvents动作\u向下、KEYCODE\u 9、动作\u向上
等都会被发送。 EditorInfo更多地基于“按键”的功能。 EditorInfo.IME\u ACTION\u SEARCH->“操作键执行“搜索”操作,将用户带到搜索他们键入的文本的结果(在任何适当的上下文中)。”

比较两者:

KEYCODE_9只是9

IME_ACTION_SEARCH是指一个键事件,表示上下文的标准实践,例如“在页面上查找”允许您键入字符串并搜索该字符串。允许您执行此操作的键将发送IME\u ACTION\u SEARCH事件

通常情况下,您没有一个指定的按钮来跨应用程序和操作系统版本进行搜索

但通常情况下,你会有一个9的口述按钮

编辑

关键事件