解決安卓全屏“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" />