软键盘“确认”、“下一步”、“搜索”等事件监听

时间:2021-06-28 00:36:56

软键盘“确认”、“下一步”、“搜索”等事件监听

    edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {  
                  
                @Override  
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {  
                    /*判断是否是“GO”键*/  
                    if(actionId == EditorInfo.IME_ACTION_GO){  
                        /*隐藏软键盘*/  
                        InputMethodManager imm = (InputMethodManager) v  
                                .getContext().getSystemService(  
                                        Context.INPUT_METHOD_SERVICE);  
                        if (imm.isActive()) {  
                            imm.hideSoftInputFromWindow(  
                                    v.getApplicationWindowToken(), 0);  
                        }  
                          
                        edittext.setText("success");  
                        webview.loadUrl(URL);  
                          
                        return true;  
                    }  
                    return false;  
                }  
            });