【发布时间】:2015-04-21 20:44:46
【问题描述】:
我有以下简单的活动:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = (WebView) findViewById(R.id.webview);
wv.setWebChromeClient(new CustomWebViewClient());
}
我为自定义 web 客户端找到了以下代码 sn-p,并希望在上述活动中使用它:
private class CustomWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.contains("mysite.com")) {
view.loadUrl(url);
} else {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
}
return true;
}
}
我得到错误:
错误:(53, 11) 错误: 类 WebView 中的方法 setWebChromeClient 不能应用于给定类型;必需:WebChromeClient 找到: MainActivity.CustomWebViewClient 原因:实际参数 MainActivity.CustomWebViewClient 无法转换为 WebChromeClient 按方法调用转换
我做错了什么?
【问题讨论】:
标签: java android webview inner-classes