解决安卓全屏“FLAG_FULLSCREEN”状态下“adjustResize”失效,全屏状态下WebView的输入框被软键盘挡住的问题
http://blog.csdn.net/l_yinghao/article/details/46008863
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 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); } }
在Activity/Fragment的onCreate()/onCreateView()里调用AndroidBug5497Workaround.assistActivity(Activity);
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //去除标题 this.requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置全屏 setContentView(R.layout.indexlayout); AndroidBug5497Workaround.assistActivity(this); onResume();//设置竖屏 dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); //欢迎信息 webView = (WebView)findViewById(R.id.webView); handler= new Handler(); //获取用户登录账户密码,跳登录 Intent intent = getIntent(); usercode = intent.getStringExtra("usercode"); Password = intent.getStringExtra("Password"); usertype = intent.getStringExtra("usertype"); webView.loadUrl("http://00000:00/Login_login.do?method=page&usercode="+usercode+"&password="+Password); }
还有个问题就是弹出键盘时候,webview会出现缩放,感觉用户体验不好,禁止页面缩放:
html界面meta标签:
<metaname="viewport"content="height= [pixel_value| "device-height"] ,width= [pixel_value| "device-width"] ,initial-scale=float_value,//初始缩放minimum-scale=float_value,//最小maximum-scale=float_value,//最大user-scalable= ["yes" | "no"]//是否允许用户对页面缩放 "/>
<meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no" />