我有一个 Webview 可以通过单击按钮打开一个 URL,但是当我在打开的网站上并按下一个链接时,它会在我的默认浏览器中打开该链接。这不是我想要它做的。谁能帮我解决这个问题?
这是我的 web.java
public class Web extends Activity {
private static final String LOG_TAG = "Web";
private WebView mWebView;
public static final String URL = "";
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.web);
mWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false);
String turl = getIntent().getStringExtra(URL);
mWebView.loadUrl(turl);
Button btnGoback = (Button) findViewById(R.id.btngoback);
// Listening to button event
btnGoback.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
finish();
}
});
}
@Override
public void onBackPressed() {
finish();
}
/**
* Provides a hook for calling "alert" from javascript. Useful for debugging
* your javascript.
*/
final class MyWebChromeClient extends WebChromeClient {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.d(LOG_TAG, message);
result.confirm();
return true;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.web, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_back:
// Single menu item is selected do something
// Ex: launching new activity/screen or show alert message
finish();
return true;
default:
return super.onOptionsItemSelected(item);}
}
}