好吧,我得到了这些错误
我不知道为什么我会得到这个,但似乎对世界其他地方来说,这对他们是有效的,如果有其他方法我必须这样做,我会改变代码,但现在看来,我的eclipse不太喜欢我
The method onKeyDown(int, KeyEvent) of type XvGForm.XvGFormClient must override or implement a supertype method
和
The method onKeyDown(int, KeyEvent) is undefined for the type WebViewClient
代码
@Override
public boolean onKeyDown (int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.canGoBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
好的,这是完整的代码
package com.xtremevisiongaming.xtremevisiongamingformapp;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.Menu;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.view.Window;
public class XvGForm extends Activity {
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xv_gform);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.xtremevisiongaming.com/forum/forum.php");
mWebView.setWebViewClient(new XvGFormClient());
}
private class XvGFormClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url)
{
webview.loadUrl(url);
return true;
}
@Override
public boolean onKeyDown (int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.canGoBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_xv_gform, menu);
return true;
}
}
最佳答案
你的问题是现在onKeyDown
函数是在private class XvGFormClient extends WebViewClient
中声明的。
你只需要用一个函数向上移动一个结束括号。我加了一些缩进,也许能帮你看出来:
private class XvGFormClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url)
{
webview.loadUrl(url);
return true;
}
}
@Override
public boolean onKeyDown (int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack(); // go back in only the web view
return true;
}
return super.onKeyDown(keyCode, event);
}
关于android - WebViewClient onKeyDown覆盖错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14844789/