2017-06-01 81 views

回答

0

我只寫這個,以便獲得url

公共類MainActivity擴展AppCompatActivity {

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 


    final Button button = new Button(this); 
    button.setText("Button"); 
    // button.setId(1); 

    final WebView webview = new WebView(this); 
    webview.setWebChromeClient(new WebChromeClient()); 


    webview.addView(button); 
    setContentView(webview); 

    button.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      String webUrl = webview.getUrl(); 
      webview.loadUrl(webUrl); 
    } 
    }); 








    webview.getSettings().setJavaScriptEnabled(true);   
    final Activity activity = this; 
    webview.setWebChromeClient(new WebChromeClient() { 
     public void onProgressChanged(WebView view, int progress) { 

      activity.setProgress(progress * 1000); 
     } 
    }); 

    webview.setWebViewClient(new WebViewClient() { 

     public void onReceivedError(WebView view, int errorCode, 
            String description, String failingUrl) { 

      Toast.makeText(activity, "Oh no! " + description, 
        Toast.LENGTH_SHORT).show(); 
     } 
    }); 
    webview.loadUrl("http://...../");   


}