I use HTML website to load in WebView, but when the user clicks in TextBox, then it hides under the keyboard. so what will be suggestion for doing this?
Staus Bar Present
If your activity is not a full screen activity then you can use android:windowSoftInputMode="adjustResize"
or android:windowSoftInputMode="adjustPan"
in your AndroidManifest.xml
to achieve this.
For Full Screen Activity
First method will not work for full screen activity. So use have to create a utility class for do this manually
Create public class WindowResize.java
public class WindowResize{ public static void assistActivity(Activity activity) { new WindowResize(activity); } private View mChildOfContent; private int usableHeightPrevious; private FrameLayout.LayoutParams frameLayoutParams; private WindowResize(final Activity activity) { FrameLayout content = activity.findViewById(android.R.id.content); mChildOfContent = content.getChildAt(0); mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { public void onGlobalLayout() { possiblyResizeChildOfContent(activity); } }); frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams(); } private void possiblyResizeChildOfContent(Activity activity) { //Visible height int usableHeightNow = computeUsableHeight(); if (usableHeightNow != usableHeightPrevious) { //Total window size. We have to decrement the SoftNavigation button height from total height if there any int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight() - getNavigationButtonHeight(activity); int heightDifference = usableHeightSansKeyboard - usableHeightNow; if (heightDifference > (usableHeightSansKeyboard / 4)) { // keyboard visible frameLayoutParams.height = usableHeightSansKeyboard - heightDifference; } else { // keyboard hidden frameLayoutParams.height = usableHeightSansKeyboard; } mChildOfContent.requestLayout(); usableHeightPrevious = usableHeightNow; } } //Usable height in current window. private int computeUsableHeight() { Rect r = new Rect(); mChildOfContent.getWindowVisibleDisplayFrame(r); return (r.bottom - r.top); } //SoftInput navigation buttons height. private int getNavigationButtonHeight(Activity activity) { // getRealMetrics is only available with API 17 and + DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); int usableHeight = metrics.heightPixels; activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics); int realHeight = metrics.heightPixels; if (realHeight > usableHeight) return realHeight - usableHeight; else return 0; } }
add WindowResize.assistActivity(this);
in main activity which contains corresponding webview.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.