Android 键盘弹出\收起及监听

1、键盘显示则隐藏,没有显示则弹出
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);
					}
				}
			});

猜你喜欢

转载自geoffrey-qiao.iteye.com/blog/2164750
今日推荐