此答案适用于 TextInputEditText :
在布局 XML 文件中,将输入法选项设置为所需的类型。例如完成。
<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textInputLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:imeOptions="actionGo"/>
</com.google.android.material.textfield.TextInputLayout>
同样,也可以将imeOptions设置为actionSubmit、actionSearch等
在 java 中添加编辑器动作监听器。
TextInputLayout textInputLayout = findViewById(R.id.textInputLayout);
textInputLayout.getEditText().setOnEditorActionListener(new 
    TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_GO) {
                performYourAction();
                return true;
            }
            return false;
        }
    });
如果您使用的是 kotlin :
textInputLayout.editText.setOnEditorActionListener { _, actionId, _ ->
    if (actionId == EditorInfo.IME_ACTION_GO) {
        performYourAction()
    }
    true
}