亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

不懂啊??!

	private?void?init()?{
		webView?=?(WebView)?findViewById(R.id.web);
		webView.loadUrl(url);
		/*
		webView.setWebViewClient(new?WebViewClient()?{
			public?boolean?shouldOverrideUrlLoading(WebView?view,?String?url)?{
				return?super.shouldOverrideUrlLoading(view,?url);
			}
		});
		*/
		WebSettings?settings?=?webView.getSettings();
		settings.setJavaScriptEnabled(true);
	}

init這么寫會使用瀏覽器,但把注釋去掉后就直接在WebView中加載了

為什么調用父類的函數會出現不同的結果??

正在回答

1 回答

shouldOverrideUrlLoading在api上的描述如下:

public boolean shouldOverrideUrlLoading (WebView view, String url)

Give the host application a chance to take over the control when a > new url is about to be loaded in the current WebView.?

If WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the url.?
If WebViewClient is provided, return true means the host application handles the url, while return false means the current WebView handles the url. This method is not called for requests using the POST "method".

Parameters

view : The WebView that is initiating the callback.

url ?: The url to be loaded.

Returns True if the host application wants to leave the current WebView and handle the url itself, otherwise return false. ? ?

翻譯一下,三種情況:

若沒有設置?WebViewClient?則在點擊鏈接之后由系統處理該 url(通常是將點擊事件作為intent對象發給系統),系統使用瀏覽器打開或彈出瀏覽器選擇對話框。

若設置?WebViewClient?且該方法返回?true?,則說明由應用的代碼處理該 url,WebView?不處理。

若設置?WebViewClient?且該方法返回?false,則說明由?WebView?處理該 url,即用?WebView?加載該 url。

很明顯,注釋后由系統處理,系統調用了瀏覽器,取消注釋調用父類方法時,父類方法的源碼如下:

@Override

public?boolean?shouldOverrideUrlLoading(WebView?view,?String?url)?{

mRedirectCount++;

mRedirectUrl?=?url;

view.loadUrl(url);

return?true;

}

最后返回的是true,即不跳轉到外部瀏覽器


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Android攻城獅的第二門課(第1季)
  • 參與學習       111145    人
  • 解答問題       1560    個

本課程由淺入深地帶您學會Android的常用控件的開發和使用

進入課程

不懂啊??!

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號