0
  1. 在这里我想在加载另一个 web 视图时加载一个 web 视图我的代码是
  2. 实际上我的主题我有两个选项,一个是 google 和 facebbok,当打开应用程序时,google 将被加载,如果我们按下 fb 按钮,facebook 将被加载,但这将花费时间
  3. 为了避免那段时间,我只想在 google 中加载 fb(仅在加载 google 时,我们必须在第二个 web 视图中加载 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");
        }
    });
    

    } }

4

1 回答 1

0
wv.loadUrl("https://www.google.com");
wv1.loadUrl("https://www.facebook.com");

同时调用这些行并从 onProgressChanged 方法中删除对 facebook url 的调用

于 2013-05-23T06:42:46.810 回答