我有一个简单的 webview 来显示一个论坛..我当然需要“映射”后退按钮才能返回论坛的网页。我以这种方式尝试过,但给了我一个致命的错误
public class MainActivity extends Activity
{
protected WebView webview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webview = (WebView) findViewById(R.id.webview);
WebSettings websettings = webview.getSettings();
websettings.setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient());
if (savedInstanceState == null)
{
webview.loadUrl("http://www.proboards.com/");
}
}
@Override
protected void onSavedInstanceState(Bundle outState) {
//super.onSavedInstanceState(outState);
webview.saveState(outState);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if(webview.canGoBack() == true)
webview.goBack();
else finish();
break;
default:
break;
}
return super.onKeyDown(keyCode, event);
}
}
错误是 onKeyDown 第 42 行。