漠视.我正在打开安装的错误应用程序.它运作得很好.:)
我的后退按钮在我的webview中正常工作,但我想知道一些事情.如何使webview返回,直到它不能再出现,而不是退出程序,让它打开一个对话框,询问用户是否确定他们不会退出.这是我对代码的看法.
感谢您抽出宝贵的时间.
.java文件
package com.vtd.whatthe;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WhatThe extends Activity {
private WebView webview;
/** Called when the activity is first created. */
public void onBackPressed (){
if (webview.isFocused() && webview.canGoBack()) {
webview.goBack();
}
else {
openMyDialog(null);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new HelloWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.setInitialScale(50);
webview.getSettings().setUseWideViewPort(true);
webview.loadUrl("http://test2.com/"); …Run Code Online (Sandbox Code Playgroud)