Androidはリターンキーの傍受を実現

1386 ワード

1.レイアウトファイルのedittext:プロパティの設定
android:singleLine="true"
android:imeOptions="actionSearch"

2.javaファイルで
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (i == EditorInfo.IME_ACTION_UNSPECIFIED) {
                    Toast.maketext(this,"      ",Toast.LENGTH_SHORT).show();
                    //     
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
                }
                return false;
            }
        });