第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

不懂?。。?/h1>
	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中加載了

為什么調(diào)用父類的函數(shù)會出現(xiàn)不同的結(jié)果??

正在回答

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. ? ?

翻譯一下,三種情況:

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

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

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

很明顯,注釋后由系統(tǒng)處理,系統(tǒng)調(diào)用了瀏覽器,取消注釋調(diào)用父類方法時,父類方法的源碼如下:

@Override

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

mRedirectCount++;

mRedirectUrl?=?url;

view.loadUrl(url);

return?true;

}

最后返回的是true,即不跳轉(zhuǎn)到外部瀏覽器


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

舉報

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

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

進入課程

不懂啊?。?/h1> 我要回答 關(guān)注問題

微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號