在App中使用Webview中的網(wǎng)頁(yè)使用了input標(biāo)簽,用于選擇文件并且上傳;
問(wèn)題:
點(diǎn)擊input標(biāo)簽 后軟鍵盤(pán)出現(xiàn),但是整體布局未向上移動(dòng),造成軟鍵盤(pán)遮擋put標(biāo)簽等。
解決方案:
簡(jiǎn)單來(lái)說(shuō)就是使用AndroidBug5497Workaround 類(lèi),在onCreate時(shí)設(shè)置
虛擬按鍵出現(xiàn)問(wèn)題
設(shè)備:紅米redmi 5 plus
類(lèi)似紅米5 plus 這樣的設(shè)備底部可能有虛擬按鍵,并且加載的網(wǎng)頁(yè)十分特殊,網(wǎng)頁(yè)底部有一個(gè)pop,如圖

image
在使用AndroidBug5497Workaround 出現(xiàn)pop(紅框部分)被底部的虛擬鍵(藍(lán)框部分)遮擋。
解決方案
* 為修復(fù)WebView內(nèi)的input 彈出軟鍵盤(pán)導(dǎo)致布局被遮擋引入
* https://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible/19494006#19494006
*/
public class AndroidBug5497Workaround {
// For more information, see https://issuetracker.google.com/issues/36911528
// 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 int frameLayoutHeight = 0;
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
frameLayoutHeight = frameLayoutParams.height;// ?。?!修改前保存原有高度
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
} else {
// keyboard probably just became hidden
if(0 != frameLayoutHeight) {
frameLayoutParams.height = frameLayoutHeight;// !??!收起鍵盤(pán)恢復(fù)原有高度
}
}
mChildOfContent.requestLayout();
usableHeightPrevious = usableHeightNow;
}
}
private int computeUsableHeight() {
Rect r = new Rect();
mChildOfContent.getWindowVisibleDisplayFrame(r);
return (r.bottom - r.top);
}
}```