阿赛·游梦鱼·郭言赛·阿赛工作室

Android中webview网页里输入框被输入法挡住

  • 发布时间: 2018年4月26日20时56分26秒 发布:asai 编辑:asai 字体:
  • put in MainActivity  onCreate{...}
    代码:

    AsaiInputMode.getInstance(this).init();
    the class code
    代码:

    package com.eesai.asai;

    import android.app.Activity;
    import android.graphics.Rect;
    import android.view.View;
    import android.view.ViewTreeObserver;
    import android.widget.FrameLayout;


    /**
    * 解决webView键盘遮挡问题的类
    */
    public class AsaiInputMode {
    private Activity activity;
    // private Handler mhanHandler;


    private View mChildOfContent;
    private int usableHeightPrevious;
    private FrameLayout.LayoutParams frameLayoutParams;

    private static AsaiInputMode keyBoardListener;


    public static AsaiInputMode getInstance(Activity activity) {
    // if(keyBoardListener==null){
    keyBoardListener=new AsaiInputMode(activity);
    // }
    return keyBoardListener;
    }


    public AsaiInputMode(Activity activity) {
    super();
    // TODO Auto-generated constructor stub
    this.activity = activity;
    // this.mhanHandler = handler;

    }


    public void init() {


    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 - r.top);
    }


    // private void showLog(String title, String msg) {
    // Log.d("Unity", title + "------------>" + msg);
    // }

    }
    • ASP
    • HTML5/CSS3/JS
    • ACCESS/MSSQL
    • 其他技术
      Powered by eesai.Com ©  2018  阿赛工作室 All Rights Reserved
      本网站由 阿赛工作室 提供源代码技术支持.  备案号:苏ICP备08114364号

      网站地图建议反馈MapRssXml回到顶部