好的,所以我得到了这些错误 我不知道为什么我得到这个,但它似乎对世界其他地方它适用于他们如果另一种方式,我必须去做这个我将改变代码,但它似乎现在我的日食不喜欢我很喜欢
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
CODE
@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;
}
}
答案 0 :(得分:3)
您的问题是,现在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);
}