private void SetMaterialHeight()
        {
            //get the MaterialViewPagerAnimator attached to this activity
            //to retrieve the declared header height
            //and set it as current view height (+10dp margin)

            MaterialViewPagerAnimator animator = MaterialViewPagerHelper.GetAnimator(Context);

            if (animator != null)
            {
                ViewGroup.LayoutParams param = LayoutParameters;
                param.Height     = (int)Math.Round(Utils.DpToPx(animator.GetHeaderHeight() + 10, Context));
                LayoutParameters = param;
            }
        }
Beispiel #2
0
        /**
         * Have to be called from WebView.WebViewClient.onPageFinished
         * ex : mWebView.setWebViewClient(new WebViewClient() { onPageFinished(WebView view, String url) { [HERE] }});
         * Inject a header to a webview : add a margin-top="**dpx"
         * Had to have a transparent background with a placeholder on top
         * So inject js for placeholder and setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); for transparency
         * TODO : inject JavaScript for Pre-Lolipop with loadUrl("js:...")
         *
         * @param webView
         * @param withAnimation if true, disapear with a fadein
         */
        public static void InjectHeader(WebView webView, bool withAnimation)
        {
            if (webView != null)
            {
                MaterialViewPagerAnimator animator = GetAnimator(webView.Context);
                if (animator != null)
                {
                    WebSettings webSettings = webView.Settings;
#pragma warning disable 618
                    webSettings.SetRenderPriority(WebSettings.RenderPriority.High);
#pragma warning restore 618
                    webSettings.CacheMode         = CacheModes.NoCache;
                    webSettings.JavaScriptEnabled = true;
                    webSettings.DomStorageEnabled = true;

                    if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
                    {
                        //transparent background
                        webView.SetLayerType(LayerType.Software, null);
                    }

                    { //inject margin top
                        int    marginTop = animator.GetHeaderHeight() + 10;
                        string js        = string.Format("document.body.style.marginTop= \"{0}px\"", marginTop);
                        WebViewLoadJs(webView, js);
                    }

                    {
                        string js = "document.body.style.backround-color= white";
                        WebViewLoadJs(webView, js);
                    }

                    if (withAnimation)
                    {
                        webView.PostDelayed(() => {
                            webView.Visibility = ViewStates.Visible;
                            ObjectAnimator.OfFloat(webView, "alpha", 0, 1).Start();
                        }, 400);
                    }
                }
            }
        }