问题描述
- 键盘的弹出事件怎么监听呀
-
聊天窗口中的listview, 键盘弹出之后一部分被压住了,要是能监听键盘弹出事件就能解决。监听edittext获得的焦点,不管用因为代码弹出键盘前就运行了 求解决 感激不尽
解决方案
解决方案二:
1、键盘显示则隐藏,没有显示则弹出
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
2、通过判断高度来判断键盘状态
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);
}
}
});
时间: 2025-01-26 18:21:44