一般 *android:windowSoftInputMode="adjustResize" *就能解决软键盘遮住输入框的问题,但是当Activity设为Full Screen这个设置就无效了。
下面这个类就能解决这个问题:

public class AndroidBugWorkaround {    // For more information, see https://code.google.com/p/android/issues/detail?id=5497    // To use this class, simply invoke assistActivity() on an Activity that already has its content view set.    public static void assistActivity (Activity activity) {        new AndroidBugWorkaround(activity);    }        private View mChildOfContent;    private int usableHeightPrevious;    private FrameLayout.LayoutParams frameLayoutParams;        private AndroidBugWorkaround(Activity activity) {        FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);        mChildOfContent = content.getChildAt(0);        mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {                public void onGlobalLayout() {                        possiblyResizeChildOfContent();                }        });        frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();    }    private void possiblyResizeChildOfContent() {        int usableHeightNow = computeUsableHeight();        if (usableHeightNow != usableHeightPrevious) {            int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();            int heightDifference = usableHeightSansKeyboard - usableHeightNow;            if (heightDifference > (usableHeightSansKeyboard/4)) {                // keyboard probably just became visible                frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;            } else {                // keyboard probably just became hidden                frameLayoutParams.height = usableHeightSansKeyboard;            }            mChildOfContent.requestLayout();            usableHeightPrevious = usableHeightNow;        }    }    private int computeUsableHeight() {        Rect r = new Rect();        mChildOfContent.getWindowVisibleDisplayFrame(r);        return r.bottom;    }}

只需要在Activity中的 onCreate() 方法中 setContentView() 后面添加
AndroidBugWorkaround.assistActivity(this);即可。

备注:computeUsableHeight() 方法返回值根据fitSystemWindows的设置值来决定,如果布局中fitsSystemWindows="false", return r.bottom; 如果fitsSystemWindows="true", return (r.bottom - r.top);

参考链接

更多相关文章

  1. Android(安卓)View类属性及方法
  2. [Android][SystemUI]navigationbar 3个虚拟键隐藏与显示
  3. Android常用Manager
  4. 从J2EE转向Android的第八天-----Toast
  5. Android基础 --- Widget
  6. android 清除所有activity
  7. RelativeLayout相对布局方法总结
  8. 浅谈Java中Collections.sort对List排序的两种方法
  9. Python list sort方法的具体使用

随机推荐

  1. qq android 软件 测试结果
  2. google地图示例
  3. VMware 虚拟机图文安装和配置 AlmaLinux
  4. 三元运算符
  5. TP 商城分类页、列表页(七)
  6. api接口和js数据获取及vue商品视图渲染
  7. classList对象与使用blur进行表单非空验
  8. CSS:flex布局:项目上的属性
  9. 自定义方法实现通过类名获取所有元素的对
  10. CSS: flex布局:容器上的属性