2017-12-03 22 views
0

私はalertDialogの中にeditTextを持っています。私はalertDialogの外をクリックすると、それは終了します。しかし、キーボードは却下されません。フォーカス変更リスナーを編集テキストに設定しました。ここでは、edittextにフォーカスがないかどうかをチェックし、キーボードを閉じます。警告ダイアログを閉じる前にSoftInputKeyboardを閉じる方法

public void onFocusChange(View v, boolean hasFocus) { 
     if (hasFocus) { 
      setClearIconVisible(isNotEmpty(getText())); 
      mInputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 
     } else { 
      setClearIconVisible(false); 
      mInputMethodManager.hideSoftInputFromWindow(this.getWindowToken(), 0); 
     } 
    } 

しかし、私はそれを閉じるためにダイアログの外をタップします。 onFocusChangeのelse部分のコードはヒットしません。誰かを助けることができる?

答えて

0

ダイアログが

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); 
alertDialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() { 
    @Override 
    public void onCancel(DialogInterface dialog) { 
     // hide softkeyboard 
    } 
}) 
+0

私はそれをやってみたのを打ち消しているときに、onCancelリスナーを設定することができます。 onCancel、mEditText.clearFocus()を実行しています。次にmInputMethodManager.hideSoftInputFromWindow(this.getWindowToken()、0)を呼び出します。しかし、私は、alertDialogが消えるとeditTextが見えなくなるので、キーボードを隠すことはないと考えています。 – user2991413

+0

キーボードを隠すことはややこしいことです。キーボードを隠す方法は?これは役に立ちますか? - https://gist.github.com/yccheok/cf4da9f2e0fa1b1d329d3f72d727696b –

関連する問題