为了避免那段时间我只想加载谷歌进行fb(只加载谷歌时我们必须在第二个网页视图中加载fb,它处于隐藏状态) 4.当用户选择fb时,我们必须在没有时间的情况下表明这一点。
public class MainActivity extends Activity {
Button google,fb;
RelativeLayout paremt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// adding webview before loading the ui design
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
final WebView wv=new WebView(MainActivity.this);
final WebView wv1=new WebView(MainActivity.this);
wv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
wv1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
wv.getSettings().setJavaScriptEnabled(true);
wv1.setVisibility(View.INVISIBLE);
wv1.getSettings().setJavaScriptEnabled(true);
paremt=(RelativeLayout)findViewById(R.id.rel2);
paremt.addView(wv);
//paremt.addView(wv1);
final Activity activity = this;
wv.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
System.out.println(" progress is "+progress);
//loading hidden webview with second link, while completion of second link
if(progress==100)
{
wv1.loadUrl("https://www.facebook.com");
}
activity.setProgress(progress * 1000);
}
});
wv.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
wv.loadUrl("https://www.google.com");
google=(Button)findViewById(R.id.button1);
fb=(Button)findViewById(R.id.button2);
int j=paremt.getChildCount();
System.out.println("aaaaaaaaaaaaaaaaaaaaa "+j);
google.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
paremt.removeAllViews();
paremt.addView(wv);
wv.setVisibility(View.VISIBLE);
}
});
fb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
paremt.removeAllViews();
wv1.setVisibility(View.VISIBLE);
paremt.addView(wv1);
wv1.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
activity.setProgress(progress * 1000);
}
});
wv1.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
//wv1.loadUrl("https://www.facebook.com");
}
});
} }
答案 0 :(得分:0)
wv.loadUrl("https://www.google.com");
wv1.loadUrl("https://www.facebook.com");
同时调用这些行并从onProgressChanged方法中删除facebook url的调用