一般 *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的singleInstance启动模式及方法调用
  2. RelativeLayout相对布局方法总结
  3. 两种button点击后改变颜色的方法selectot和重写
  4. Android中设置屏幕全屏两种方法:
  5. Android性能优化的一些方法
  6. Android 4.0.3 源码编译中添加外部jar包和外部so到apk的方法
  7. Android中两种设置全屏的方法
  8. android实现字体闪烁动画的方法

随机推荐

  1. Android 拦截 接收 短信
  2. Android开发:javah的使用方法
  3. 相对布局 relativelayout
  4. 网络框架之Glide
  5. Android简单计时器
  6. Android webview中拦截超链接
  7. cryptfs-password-manager, Android设备
  8. Android(安卓)SD卡中压缩包解压(ZIP文件)
  9. Android来电拦截的实现方法
  10. Android 生成图标的有力工具 Android Ass