From a2ad006a7e58ba218856a323f3864de71c5cc2d2 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 24 Nov 2022 13:45:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BF=83=E6=84=BF=E5=8D=95?= =?UTF-8?q?=E9=AB=98=E5=BA=A6=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yunbao/common/activity/WebViewActivity.java | 2 +- .../com/yunbao/common/utils/JavascriptInterfaceUtils.java | 8 ++++++-- .../java/com/yunbao/live/dialog/LiveHDDialogFragment.java | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java b/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java index 7fa7dc562..8856fff3a 100644 --- a/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java +++ b/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java @@ -98,7 +98,7 @@ public class WebViewActivity extends AbsActivity { } //屏幕高度-ft_title的paddingTop int height = DeviceUtils.getScreenHeight(mContext)-DpUtil.dp2px(24); - view.loadUrl("javascript:window.androidObject.setHeight("+height+",0)"); + view.loadUrl("javascript:window.androidObject.setHeight("+height+",0,false)"); } }); diff --git a/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java b/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java index db761f3ef..cc1d35230 100644 --- a/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java +++ b/common/src/main/java/com/yunbao/common/utils/JavascriptInterfaceUtils.java @@ -476,8 +476,12 @@ public class JavascriptInterfaceUtils { } + /** + * 设置webView高度 + * @param useDp 是否用dp换算 + */ @JavascriptInterface - public void setHeight(String height, String width) { + public void setHeight(String height, String width,boolean useDp) { if ("0".equals(height)) { return; } @@ -487,7 +491,7 @@ public class JavascriptInterfaceUtils { if("-1".equals(height)){ params.height=ViewGroup.LayoutParams.MATCH_PARENT; }else { - params.height = Integer.parseInt(height); + params.height = useDp?DpUtil.dp2px(Integer.parseInt(height)):Integer.parseInt(height); } mWebView.setLayoutParams(params); mWebView.setVisibility(View.VISIBLE); diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveHDDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveHDDialogFragment.java index 98b264141..f89194d4d 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveHDDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveHDDialogFragment.java @@ -192,7 +192,7 @@ public class LiveHDDialogFragment extends AbsDialogFragment { @Override public void onPageFinished(WebView view, String url) { - view.loadUrl("javascript:window.androidObject.setHeight(document.body.clientHeight,document.body.clientWidth)"); + view.loadUrl("javascript:window.androidObject.setHeight(document.body.clientHeight,document.body.clientWidth,true)"); if (listener != null) { listener.onShow(LiveHDDialogFragment.this.getDialog()); listener = null;