title: Button for copying url- webview
body: <p>i'm working on a webview project, in which i don't have a url bar, so i want a button in the webview's layout that would copy the current page URL on the clipboard so that i can paste it somewhere else. </p>
  
  <p>Thanks </p>
  
  <p>below is my code -</p>
  
  <pre><code>package com.Exmple.avd;
  </code></pre>
  
  <p>package com.ApkEngine.avd;</p>
  
  <pre><code>import android.app.Activity;
  import android.content.ClipData;
  import android.content.ClipboardManager;
  import android.os.Bundle;
  import android.view.KeyEvent;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.widget.Button;
  
  public class Search extends Activity {
  
  private WebView mWebView;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_search);
      Button button = (Button) findViewById(R.id.button1);
  
      button.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View view) {
  
          String url = mWebView.getUrl();
          ClipboardManager clipboard = (ClipboardManager)     getSystemService(CLIPBOARD_SERVICE); 
          ClipData clip = ClipData.newPlainText("label", url);
          clipboard.setPrimaryClip(clip);
  
          }
  
      });
      mWebView = (WebView) findViewById(R.id.wvsearch);
      mWebView.getSettings().setJavaScriptEnabled(true);
      mWebView.setWebViewClient(new HelloWebViewClient());
      mWebView.getSettings().setBuiltInZoomControls(true);
      mWebView.loadUrl("http://www.google.com"); 
  }
   private class HelloWebViewClient extends WebViewClient {
  @Override
  public boolean shouldOverrideUrlLoading(WebView webview, String url)
  {
  
  
  webview.loadUrl(url);
  return true;
  }
  }
  
   @Override
   public boolean onKeyDown(int keyCode, KeyEvent event)
   {
  
   if ((keyCode == KeyEvent.KEYCODE_BACK) &amp;&amp; mWebView.canGoBack())
  
  {
  mWebView.goBack();
  return true;
  }
  return super.onKeyDown(keyCode, event);
  
  
   }
  }
  </code></pre>