`
Mr.Joe
  • 浏览: 134770 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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);
					}
				}
			});
0
5
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics