我无法在一定条件下关闭软输入

时间:2016-03-02 07:12:26

标签: android android-softkeyboard android-dialog

如果我添加了deley,它就有效。这是什么原因?

 final AlertDialog dialog0 = new AlertDialog.Builder(this)
                .setTitle("0")
                .setView(view)
                .show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                final AlertDialog dialog1 = new AlertDialog.Builder(TestActvt.this).setTitle("1").setMessage("222").show();

                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {

                        dialog1.dismiss();
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
//                                new Handler().postDelayed(new Runnable() {
//                                    @Override
//                                    public void run() {
                                        dialog0.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
                                        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
                                        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                                        view.requestFocus();
                                        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
//                                    }
//                                },1000);
                            }
                        },100);

                    }
                },3000);
            }
        },3000);

1 个答案:

答案 0 :(得分:0)

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);