30

xmlに7つのエディットテキストボックスがあります。OnFocusChangeListenerを使用して編集テキストから値を読み取り、その値を計算に使用しています。ソフトキーボードの[完了]ボタンをクリックすると、編集テキストのフォーカスが失われるようにします。エディットテキストの値。

4

4 に答える 4

77

ソフトキーボードから完了ボタンをクリックするとフォーカスを失うclearFocusメソッドを呼び出します。EditText次のようにします。

editText.setOnEditorActionListener(new OnEditorActionListener() {        
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if(actionId==EditorInfo.IME_ACTION_DONE){
            //Clear focus here from edittext
             editText.clearFocus();
        }
    return false;
    }
});

android:imeOptions="actionDone"また、edittextxmlを追加します

于 2012-08-16T06:31:48.097 に答える
2

アクティビティで一度にすべての焦点を外す方法を考えている人がこの質問に出くわした場合は、親のレイアウト(またはそのことについては任意のレイアウト)に焦点を合わせることができます。

findViewById(R.id.myLayout).requestFocus();
于 2019-01-16T21:28:15.847 に答える
0

もう少し完全な答え

//  This will change the ‘RETURN’ button in your the EditText’s soft keyboard to a ‘DONE’ button.
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
//  Use the InputMethodManager to close the soft keyboard
editText.setOnEditorActionListener(new OnEditorActionListener() {        
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if(actionId==EditorInfo.IME_ACTION_DONE){
            //Clear focus here from edittext
            InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
    return false;
    }
});
于 2019-06-06T17:27:19.673 に答える
0

Kotlin、それは私のために働いた:

main.clearFocus()

mainはルートConstraintLayoutです

于 2019-11-10T14:57:54.250 に答える