Hide Soft keyboard on return key press

前端 未结 9 1244
[愿得一人]
[愿得一人] 2020-12-29 19:00

I\'ve searched half a dozen other answers on SO, but haven\'t found one that works. All I\'m trying to do is dismiss the soft keyboard when the user presses the enter butto

9条回答
  •  [愿得一人]
    2020-12-29 19:53

    EditText.xml

    
    

    Fragment.java

    final EditText edit_text_searh = (EditText) v.findViewById(R.id.edit_text_searh_home);
    
        edit_text_searh.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(edit_text_searh.getWindowToken(), 0);
    
                Toast.makeText(getContext(),edit_text_searh.getText(),Toast.LENGTH_SHORT).show();
                return true;
    
            }
        });
    

提交回复
热议问题