98、EditText 按键盘查询 触发事件

只需要在XML在输入框中加入Android:imeOptions=”actionSearch”,调用软键盘时,回车键就会显示搜索二字。

editSearch.setOnEditorActionListener(new editActionListener());
class editActionListener implements TextView.OnEditorActionListener {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            ((InputMethodManager) editSearch.getContext().getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(
                            mActivity.getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);

            这里可以操作你要的东东。。。。。。。return true;
        }
        return false;
    }
}

在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode=”adjustPan”可以防止软键盘会把原来的界面挤上去的问题

原文地址:https://www.cnblogs.com/androidsj/p/5598106.html