如何检查是否单击了键盘上的输入?

How can I check if enter on my keyboard is clicked?

此问题不重复。

我想检查我键盘上的 enter 是否被点击。

这段代码对我最有帮助:

 edittext.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            Toast.makeText(getActivity(), "it works", Toast
                    .LENGTH_SHORT).show();
            return false;
        }
    });

但它只适用于我电脑的键盘,而不适用于我的 phone。 我不知道天气很重要,但我正在使用 Fragment。

这是我的 XML:

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@null"
    android:id="@+id/edittext"
    android:imeOptions="actionDone"
    android:padding="10dp"/>

我查看了 ALL These acticles 并尝试了所有代码,但没有任何效果。

编辑

我看了一条评论,所以我想补充:

我说的是软键盘。

依赖于android:imeOptions=""你的EditText。 例如,android:imeOptions="actionDone":

editText.setOnEditorActionListener(new OnEditorActionListener() {        
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if(actionId == EditorInfo.IME_ACTION_DONE){
            //do something
        }
    return false;
    }
});

更新: 将 android:inputType="text" 添加到 xml 文件

中的 EditText
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@null"
    android:id="@+id/edittext"
    android:inputType="text"
    android:imeOptions="actionDone"
    android:padding="10dp"/>