Doneオンスクリーンキーボードのキーが押されたことを検出することはできますか?
Doneオンスクリーンキーボードのキーが押されたことを検出することはできますか?
回答:
はい、可能です:
editText = (EditText) findViewById(R.id.edit_text);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// do your stuff here
}
return false;
}
});
次のライブラリをインポートする必要があることに注意してください。
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;
Editor Infoは、Androidアプリケーションで任意のタイプのユーザー入力を処理する必要がある場合に最も便利なクラスです。たとえば、ログイン/登録/検索操作では、より正確なキーボード入力に使用できます。エディター情報クラスは、インプットメソッドがエディットテキストコンテンツと直接通信するテキスト編集オブジェクトのいくつかの属性を記述します。
IME_ACTION_DONEで試すことができます。
このアクションは、Done何も入力せずに操作を実行し、IMEが閉じられます。
EditTextObj.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_DONE) {
/* Write your logic here that will be executed when user taps next button */
handled = true;
}
return handled;
}
});
バターナイフを使用すると、これを行うことができます
@OnEditorAction(R.id.signInPasswordText)
boolean onEditorAction(TextView v, int actionId, KeyEvent event){
if (actionId == EditorInfo.IME_ACTION_DONE || event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
/* Write your logic here that will be executed when user taps next button */
}
return false;
}
EditorInfo.IME_ACTION_SEARCH代わりにレンズ検索ボタンを使用する必要がありました。