我在我的第一个活动中有两个按钮说 A,我在第二个活动中有一个 webview 说 B 现在我想在按钮点击事件的 webview 中加载 url。如果我点击 btn1 按钮,那么 webview 应该显示 google.com 网站,如果我点击 btn2 按钮,那么 webview 应该显示 gmail.com 网站,这是我的 A 和 B 活动代码。提前致谢
活动 A 代码
Button btn1 = (Button) findViewById(R.id.btn_google);
btn1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent (google.this,webview.class);
google.this.startActivity(intent);
}
}
);
Button btn2 = (Button) findViewById(R.id.btn_gmail);
btn_signup.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent (google.this,webview.class);
google.this.startActivity(intent);
}
}
);
这是活动B的代码
super.onCreate(savedInstanceState);
setContentView(R.layout.webview );
WebViewClient yourWebClient = new WebViewClient()
{
// Override page so it's load on my view only
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
// This line we let me load only pages inside Firstdroid Webpage
view.loadUrl(url);
// Load new URL Don't override URL Link
// Return true to override url loading (In this case do nothing).
return true;
}
};
// Get Web view
mWebView = (WebView) findViewById( R.id.mywebview ); //This is the id you gave
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setSupportZoom(true); //Zoom Control on web (You don't need this
//if ROM supports Multi-Touch
mWebView.getSettings().setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM
mWebView.setWebViewClient(yourWebClient);
mWebView.reload();
}