我想将此代码添加到我的 java 文件中:
webView.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("http://")) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
}
但我不知道在哪里。这是我的java文件:package sheddle.donald.duck.app;导入android.app.Activity;导入android.os.Bundle;导入android.view.Window;导入 android.webkit.WebChromeClient;导入 android.webkit.WebView;导入 android.webkit.WebViewClient;公共类 WebPageLoader 扩展 Activity { WebView webview;
final Activity activity = this;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webview.getSettings().setSupportMultipleWindows(true);
webview.getSettings().setPluginsEnabled(true);
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webview.loadUrl("http://www.sherdle.com/apphosting/dd");
}
@Override
public void onBackPressed (){
if(webview.canGoBack()) webview.goBack();
else super.onBackPressed();
}
}
我是 android 新手,我所做的一切都需要很多帮助。谢谢你的帮助。
我现在已经有了这个:package sheddle.donald.duck.app; 导入android.app.Activity;导入android.os.Bundle;导入android.view.Window;导入 android.webkit.WebChromeClient;导入 android.webkit.WebView;导入 android.webkit.WebViewClient;公共类 WebPageLoader 扩展 Activity { WebView webview;
final Activity activity = this;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webview.getSettings().setSupportMultipleWindows(true);
webview.getSettings().setPluginsEnabled(true);
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webview.setWebChromeClient(new WebChromeClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("http://")) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
webview.loadUrl("http://www.sherdle.com/apphosting/dd");
}
@Override
public void onBackPressed (){
if(webview.canGoBack()) webview.goBack();
else super.onBackPressed();
}
}
但我在我的 LoadUrl 行上收到此错误:此行有多个标记 - 语法错误,插入“AssignmentOperator 表达式”以完成表达式 - 语法错误,插入“;” 完成 FieldDeclaration - 语法错误,插入“)” 完成 MethodInvocation - 语法错误,插入“}” 完成 ClassBody - 语法错误,插入“;” 完成语句 - 标记上的语法错误,错误的构造