解决安卓全屏“FLAG_FULLSCREEN”状态下“adjustResize”失效,全屏状态下WebView的输入框被软键盘挡住的问题

沿着这个问题的线索,可以追溯到: http://code.google.com/p/android/issues/detail?id=5497    ,安卓官方问题回馈帖,这个问题的代号为“ 5497 ” ,就这个问题帖的回复来看,该问题困惑了许多人数年之久,问题发布日期“ Dec 16, 2009 ”,现在我在安卓 4.4.2 环境运行,这个问题依旧存在。在此推荐这其中的一个解决方法,来自:stackoverflow.com,实测有效。
[java]  view plain copy print ?
  1. public class AndroidBug5497Workaround {  
  2.   
  3.     // For more information, see https://code.google.com/p/android/issues/detail?id=5497  
  4.     // To use this class, simply invoke assistActivity() on an Activity that already has its content view set.  
  5.   
  6.     public static void assistActivity (Activity activity) {  
  7.         new AndroidBug5497Workaround(activity);  
  8.     }  
  9.   
  10.     private View mChildOfContent;  
  11.     private int usableHeightPrevious;  
  12.     private FrameLayout.LayoutParams frameLayoutParams;  
  13.   
  14.     private AndroidBug5497Workaround(Activity activity) {  
  15.         FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);  
  16.         mChildOfContent = content.getChildAt(0);  
  17.         mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {  
  18.             public void onGlobalLayout() {  
  19.                 possiblyResizeChildOfContent();  
  20.             }  
  21.         });  
  22.         frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();  
  23.     }  
  24.   
  25.     private void possiblyResizeChildOfContent() {  
  26.         int usableHeightNow = computeUsableHeight();  
  27.         if (usableHeightNow != usableHeightPrevious) {  
  28.             int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();  
  29.             int heightDifference = usableHeightSansKeyboard - usableHeightNow;  
  30.             if (heightDifference > (usableHeightSansKeyboard/4)) {  
  31.                 // keyboard probably just became visible  
  32.                 frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;  
  33.             } else {  
  34.                 // keyboard probably just became hidden  
  35.                 frameLayoutParams.height = usableHeightSansKeyboard;  
  36.             }  
  37.             mChildOfContent.requestLayout();  
  38.             usableHeightPrevious = usableHeightNow;  
  39.         }  
  40.     }  
  41.   
  42.     private int computeUsableHeight() {  
  43.         Rect r = new Rect();  
  44.         mChildOfContent.getWindowVisibleDisplayFrame(r);  
  45.         return (r.bottom - r.top);  
  46.     }  
  47.   
  48. }  

在Activity/Fragment的onCreate()/onCreateView()里调用AndroidBug5497Workaround.assistActivity(Activity);代码搬运,希望能够帮助到各位。感谢答案提供者,祝生活愉快。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值