日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

全屏显示的包含webview的页面中弹出的软键盘覆盖输入框的问题

發布時間:2024/4/15 编程问答 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 全屏显示的包含webview的页面中弹出的软键盘覆盖输入框的问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

備注 1.使用adjustResize屬性時,如果界面中沒有滾動條,需要添加一個滾動條scrollview包裹所有內容,保證resize后 能滾動顯示顯示不下的內容 2.全屏fullscreen模式時 adjustResize屬性失效,屬于是一個bug,只能使用adjustPan 來設置焦點 3.全屏fullscreen模式時 webview adjustPan 偶爾也會失效

首先,在全屏的狀態下,android:windowSoftInputMode="adjustResize"屬性是不起作用的,官方文檔中有記錄: Window flag: hide all screen decorations (such as the status bar) while this window is displayed. This allows the window to use the entire display space for itself -- the status bar will be hidden when an app window with this flag set is on the top layer. A fullscreen window will ignore a value of SOFT_INPUT_ADJUST_RESIZE for the window's softInputMode field; the window will stay fullscreen and will not resize. 大意就是說在全屏狀態下,會忽略SOFT_INPUT_ADJUST_RESIZE屬性。而全屏狀態下設置為android:windowSoftInputMode="adjustPan"也不一定會起作用。

http://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible/19494006#19494006在此找到了解決方法。

<!-- lang: java -->public class AndroidBug5497Workaround {// 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 AndroidBug5497Workaround(activity);}private View mChildOfContent;private int usableHeightPrevious;private FrameLayout.LayoutParams frameLayoutParams;private AndroidBug5497Workaround(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 visibleframeLayoutParams.height = usableHeightSansKeyboard - heightDifference;} else {// keyboard probably just became hiddenframeLayoutParams.height = usableHeightSansKeyboard;}mChildOfContent.requestLayout();usableHeightPrevious = usableHeightNow;}}private int computeUsableHeight() {Rect r = new Rect();mChildOfContent.getWindowVisibleDisplayFrame(r);return (r.bottom - r.top);}}

只要在setContentvView之后調用assistActivity 方法即可。 在具體使用時發現有時鍵盤彈出后點擊空白處隱藏鍵盤,布局并沒有恢復全屏,發現是有時候OnGlobalLayoutListener監聽并沒有被觸發,后替換成OnPreDrawListener監聽即可。 經多個模擬器與真機測試,發現OnGlobalLayoutListener可以正常使用,應該是個別系統問題

轉載于:https://my.oschina.net/u/1409622/blog/310631

總結

以上是生活随笔為你收集整理的全屏显示的包含webview的页面中弹出的软键盘覆盖输入框的问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。