From 81b67c3bf28d43976dc1250e6918006656c00913 Mon Sep 17 00:00:00 2001 From: youlookwhat <770413277@qq.com> Date: Thu, 28 Oct 2021 22:44:09 +0800 Subject: [PATCH] add ByWebView get() --- .../main/java/me/jingbin/web/ByWebView.java | 19 +++++++++++-------- .../webviewstudy/ui/ByWebViewActivity.java | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ByWebView/src/main/java/me/jingbin/web/ByWebView.java b/ByWebView/src/main/java/me/jingbin/web/ByWebView.java index 41d3e85..c751b23 100644 --- a/ByWebView/src/main/java/me/jingbin/web/ByWebView.java +++ b/ByWebView/src/main/java/me/jingbin/web/ByWebView.java @@ -6,7 +6,6 @@ import android.os.Build; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; import android.text.TextUtils; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -325,7 +324,6 @@ public void setFixScreenLandscape(boolean fixScreenLandscape) { public static class Builder { private Activity mActivity; - private Fragment mFragment; // 默认使用进度条 private boolean mUseWebProgress = true; // 进度条 开始颜色 @@ -351,11 +349,6 @@ public Builder(Activity activity) { this.mActivity = activity; } - public Builder(Activity activity, Fragment fragment) { - this.mActivity = activity; - this.mFragment = fragment; - } - /** * WebView容器 */ @@ -477,8 +470,18 @@ public Builder setOnByWebClientCallback(OnByWebClientCallback onByWebClientCallb return this; } + /** + * 直接获取ByWebView,避免一定要调用loadUrl()才能获取ByWebView的情况 + */ + public ByWebView get() { + return new ByWebView(this); + } + + /** + * loadUrl()并获取ByWebView + */ public ByWebView loadUrl(String url) { - ByWebView byWebView = new ByWebView(this); + ByWebView byWebView = get(); byWebView.loadUrl(url); return byWebView; } diff --git a/app/src/main/java/com/example/jingbin/webviewstudy/ui/ByWebViewActivity.java b/app/src/main/java/com/example/jingbin/webviewstudy/ui/ByWebViewActivity.java index 853a4aa..879bb54 100644 --- a/app/src/main/java/com/example/jingbin/webviewstudy/ui/ByWebViewActivity.java +++ b/app/src/main/java/com/example/jingbin/webviewstudy/ui/ByWebViewActivity.java @@ -264,7 +264,7 @@ private void getDataFromBrowser(Intent intent) { String text = "Scheme: " + scheme + "\n" + "host: " + host + "\n" + "path: " + path; Log.e("data", text); String url = scheme + "://" + host + path; - webView.loadUrl(url); + byWebView.loadUrl(url); } catch (Exception e) { e.printStackTrace(); }