应用场景:

manifest中activity设置如下属性:

android:windowSoftInputMode="stateHidden"android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"

 此时按照网上搜索的通常方法,重写linearLayout,会不起作用,因为layout的bottom属性在全屏中不变。

改用api 1就有ViewTreeObserver来监听layout变化:

//获取最外层Layoutfinal View rootView=((ViewGroup)findViewById(android.R.id.content)).getChildAt(0);rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {@Overridepublic void onGlobalLayout() {                                Rect rect = new Rect();rootView.getWindowVisibleDisplayFrame(rect);int rootHeight=rootView.getRootView().getHeight();int displayHeight=rect.height();                                int diffHeight=rootHeight-displayHeight;if(diffHeight==0){                                //键盘收起                                }else{                                //键盘弹出                                }                      }});

 

PS:渣排版,轻拍

更多相关文章

  1. android 输入键盘遮挡页面的问题
  2. Android 命名空间和自定义属性
  3. android 神奇的android:clipChildren属性
  4. 识别你的手机 Android的属性系统

随机推荐

  1. Android中使用硬盘模拟SD卡
  2. Android(安卓)ListView城市列表,按a-z分
  3. 我的android开发学习之路
  4. Android(安卓)FileProvider应用之间共享
  5. Android系统框架
  6. Android(安卓)Studio 第一次新建Android(
  7. 2011年linux数据库的android在线分享
  8. App测试中ios和Android的区别
  9. android 两个应用之间的通信与调用
  10. Android第三方库