InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
通过判断高度来判断键盘状态
detailMainRL = (RelativeLayout) findViewById(R.id.home_news_detail_main_rl); detailMainRL.getViewTreeObserver().addOnGlobalLayoutListener( new OnGlobalLayoutListener(){ @Override public void onGlobalLayout() { int heightDiff = detailMainRL.getRootView().getHeight() - detailMainRL.getHeight(); Log.v(TAG, "detailMainRL.getRootView().getHeight() = " + detailMainRL.getRootView().getHeight()); Log.v(TAG, "detailMainRL.getHeight() = " + detailMainRL.getHeight()); if (heightDiff > 100) { // 说明键盘是弹出状态 Log.v(TAG, "键盘弹出状态"); commentBoxRL.setVisibility(View.VISIBLE); } else{ Log.v(TAG, "键盘收起状态"); commentBoxRL.setVisibility(View.GONE); } } });